All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: linux-crypto@vger.kernel.org,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>
Cc: phone-devel@vger.kernel.org, Stefan Hansson <newbyte@disroot.org>,
	Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH 14/15 v2] crypto: ux500/hash: Use AMBA core primecell IDs
Date: Mon, 25 Jul 2022 16:05:03 +0200	[thread overview]
Message-ID: <20220725140504.2398965-15-linus.walleij@linaro.org> (raw)
In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org>

Use the AMBA (PrimeCell) bus core define and read 32bit
CID and PID from the peripheral, then check those.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Initialized both CID and PID to 0 appropriately.
---
 drivers/crypto/ux500/hash/hash_alg.h  | 11 ++---------
 drivers/crypto/ux500/hash/hash_core.c | 25 ++++++++++++++++++-------
 2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/drivers/crypto/ux500/hash/hash_alg.h b/drivers/crypto/ux500/hash/hash_alg.h
index cc44d3cb21ac..96c614444fa2 100644
--- a/drivers/crypto/ux500/hash/hash_alg.h
+++ b/drivers/crypto/ux500/hash/hash_alg.h
@@ -63,15 +63,8 @@
 #define HASH_STR_NBLW_MASK	0x0000001FUL
 #define HASH_NBLW_MAX_VAL	0x1F
 
-/* PrimeCell IDs */
-#define HASH_P_ID0		0xE0
-#define HASH_P_ID1		0x05
-#define HASH_P_ID2		0x38
-#define HASH_P_ID3		0x00
-#define HASH_CELL_ID0		0x0D
-#define HASH_CELL_ID1		0xF0
-#define HASH_CELL_ID2		0x05
-#define HASH_CELL_ID3		0xB1
+/* PrimeCell ID */
+#define UX500_HASH_PID		0x003805E0U
 
 /* Hardware access method */
 enum hash_mode {
diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c
index 914c35919570..71ed2a573714 100644
--- a/drivers/crypto/ux500/hash/hash_core.c
+++ b/drivers/crypto/ux500/hash/hash_core.c
@@ -13,6 +13,7 @@
 
 #define pr_fmt(fmt) "hashX hashX: " fmt
 
+#include <linux/amba/bus.h>
 #include <linux/clk.h>
 #include <linux/device.h>
 #include <linux/dma-mapping.h>
@@ -949,18 +950,28 @@ int hash_check_hw(struct hash_device_data *device_data)
 	unsigned int regs[] = { UX500_HASH_PERIPHID0, UX500_HASH_PERIPHID1,
 		UX500_HASH_PERIPHID2, UX500_HASH_PERIPHID3, UX500_HASH_CELLID0,
 		UX500_HASH_CELLID1, UX500_HASH_CELLID2, UX500_HASH_CELLID3 };
-	unsigned int expected[] = { HASH_P_ID0, HASH_P_ID1, HASH_P_ID2, HASH_P_ID3,
-		HASH_CELL_ID0, HASH_CELL_ID1, HASH_CELL_ID2, HASH_CELL_ID3 };
 	unsigned int val;
+	u32 pid = 0;
+	u32 cid = 0;
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(regs); i++) {
 		regmap_read(device_data->map, regs[i], &val);
-		if (val != expected[i]) {
-			dev_err(device_data->dev, "ID word %d was %08x expected %08x\n",
-				i, val, expected[i]);
-			return -ENODEV;
-		}
+		if (i < 4)
+			pid |= (val & 255) << (i * 8);
+		else
+			cid |= (val & 255) << ((i - 4) * 8);
+	}
+
+	if (cid != AMBA_CID) {
+		dev_err(device_data->dev, "AMBA CID was %08x expected %08x\n",
+			cid, AMBA_CID);
+		return -ENODEV;
+	}
+	if (pid != UX500_HASH_PID) {
+		dev_err(device_data->dev, "PID was %08x expected %08x\n",
+			pid, UX500_HASH_PID);
+		return -ENODEV;
 	}
 
 	return 0;
-- 
2.36.1


  parent reply	other threads:[~2022-07-25 14:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-25 14:04 [PATCH 00/15 v2] Ux500 hash cleanup Linus Walleij
2022-07-25 14:04 ` [PATCH 01/15 v2] crypto: ux500/hash: Pass ctx to hash_setconfiguration() Linus Walleij
2022-07-25 14:04 ` [PATCH 02/15 v2] crypto: ux500/hash: Get rid of custom device list Linus Walleij
2022-07-25 14:04 ` [PATCH 03/15 v2] crypto: ux500/hash: Pass context to zero message digest Linus Walleij
2022-07-25 14:04 ` [PATCH 04/15 v2] crypto: ux500/hash: Drop custom state save/restore Linus Walleij
2022-07-25 14:04 ` [PATCH 05/15 v2] crypto: ux500/hash: Drop bit index Linus Walleij
2022-07-25 14:04 ` [PATCH 06/15 v2] crypto: ux500/hash: Break while/do instead of if/else Linus Walleij
2022-07-25 14:04 ` [PATCH 07/15 v2] crypto: ux500/hash: Rename and switch type of member Linus Walleij
2022-07-25 14:04 ` [PATCH 08/15 v2] crypto: ux500/hash: Stop saving/restoring compulsively Linus Walleij
2022-07-25 14:04 ` [PATCH 09/15 v2] crypto: ux500/hash: Get rid of state from request context Linus Walleij
2022-07-25 14:04 ` [PATCH 10/15 v2] crypto: ux500/hash: Implement .export and .import Linus Walleij
2022-07-25 14:05 ` [PATCH 11/15 v2] crypto: ux500/hash: Drop custom uint64 type Linus Walleij
2022-07-25 14:05 ` [PATCH 12/15 v2] crypto: ux500/hash: Drop regulator handling Linus Walleij
2022-07-25 14:05 ` [PATCH 13/15 v2] crypto: ux500/hash: Convert to regmap MMIO Linus Walleij
2022-07-25 14:05 ` Linus Walleij [this message]
2022-07-25 14:05 ` [PATCH 15/15 v2] crypto: ux500/hash: Implement runtime PM Linus Walleij

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=20220725140504.2398965-15-linus.walleij@linaro.org \
    --to=linus.walleij@linaro.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=newbyte@disroot.org \
    --cc=phone-devel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.