Skip to content

Commit b9957fc

Browse files
martin-kaiserherbertx
authored andcommitted
hwrng: imx-rngc - check the rng type
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. Reviewed-by: PrasannaKumar Muralidharan <[email protected]> Signed-off-by: Martin Kaiser <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent f7d7945 commit b9957fc

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

drivers/char/hw_random/imx-rngc.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@
1818
#include <linux/completion.h>
1919
#include <linux/io.h>
2020

21+
#define RNGC_VER_ID 0x0000
2122
#define RNGC_COMMAND 0x0004
2223
#define RNGC_CONTROL 0x0008
2324
#define RNGC_STATUS 0x000C
2425
#define RNGC_ERROR 0x0010
2526
#define RNGC_FIFO 0x0014
2627

28+
/* the fields in the ver id register */
29+
#define RNGC_TYPE_SHIFT 28
30+
#define RNGC_VER_MAJ_SHIFT 8
31+
32+
/* the rng_type field */
33+
#define RNGC_TYPE_RNGB 0x1
34+
#define RNGC_TYPE_RNGC 0x2
35+
36+
2737
#define RNGC_CMD_CLR_ERR 0x00000020
2838
#define RNGC_CMD_CLR_INT 0x00000010
2939
#define RNGC_CMD_SEED 0x00000002
@@ -212,6 +222,8 @@ static int imx_rngc_probe(struct platform_device *pdev)
212222
struct imx_rngc *rngc;
213223
int ret;
214224
int irq;
225+
u32 ver_id;
226+
u8 rng_type;
215227

216228
rngc = devm_kzalloc(&pdev->dev, sizeof(*rngc), GFP_KERNEL);
217229
if (!rngc)
@@ -237,6 +249,17 @@ static int imx_rngc_probe(struct platform_device *pdev)
237249
if (ret)
238250
return ret;
239251

252+
ver_id = readl(rngc->base + RNGC_VER_ID);
253+
rng_type = ver_id >> RNGC_TYPE_SHIFT;
254+
/*
255+
* This driver supports only RNGC and RNGB. (There's a different
256+
* driver for RNGA.)
257+
*/
258+
if (rng_type != RNGC_TYPE_RNGC && rng_type != RNGC_TYPE_RNGB) {
259+
ret = -ENODEV;
260+
goto err;
261+
}
262+
240263
ret = devm_request_irq(&pdev->dev,
241264
irq, imx_rngc_irq, 0, pdev->name, (void *)rngc);
242265
if (ret) {
@@ -269,7 +292,10 @@ static int imx_rngc_probe(struct platform_device *pdev)
269292
goto err;
270293
}
271294

272-
dev_info(&pdev->dev, "Freescale RNGC registered.\n");
295+
dev_info(&pdev->dev,
296+
"Freescale RNG%c registered (HW revision %d.%02d)\n",
297+
rng_type == RNGC_TYPE_RNGB ? 'B' : 'C',
298+
(ver_id >> RNGC_VER_MAJ_SHIFT) & 0xff, ver_id & 0xff);
273299
return 0;
274300

275301
err:

0 commit comments

Comments
 (0)