1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2017-2019 NXP
4  *
5  * Brief   Random Number Generator Registers.
6  */
7 #ifndef __RNG_REGS_H__
8 #define __RNG_REGS_H__
9 
10 #include <util.h>
11 
12 /*
13  * RNG Test Registers
14  */
15 /* Miscellaneous Control */
16 #define TRNG_MCTL						0x0600
17 #define TRNG_MCTL_PRGM					BIT32(16)
18 #define TRNG_MCTL_ERR					BIT32(12)
19 #define TRNG_MCTL_ACC					BIT32(5)
20 #define BM_TRNG_MCTL_SAMP_MODE			SHIFT_U32(0x3, 0)
21 /* Use raw data in both entropy shifter and statistical checker */
22 #define TRNG_MCTL_SAMP_MODE_RAW_ES_SC	SHIFT_U32(1, 0)
23 
24 /* Seed Control */
25 #define TRNG_SDCTL			0x0610
26 #define BM_TRNG_SDCTL_ENT_DLY		SHIFT_U32(0xFFFF, 16)
27 #define GET_TRNG_SDCTL_ENT_DLY(val)	(((val) & BM_TRNG_SDCTL_ENT_DLY) >> 16)
28 #define TRNG_SDCTL_ENT_DLY(val)		SHIFT_U32(((val) & 0xFFFF), 16)
29 #define TRNG_SDCTL_SAMP_SIZE(val)	((val) & 0xFFFF)
30 
31 #ifdef CFG_MX6SX
32 #define TRNG_SDCTL_ENT_DLY_MIN 12000
33 #else
34 #define TRNG_SDCTL_ENT_DLY_MIN		3200
35 #endif
36 #define TRNG_SDCTL_ENT_DLY_MAX 12800
37 
38 /* Frequency Count Minimum Limit */
39 #define TRNG_FRQMIN			0x0618
40 /* Frequency Count Maximum Limit */
41 #define TRNG_FRQMAX			0x061C
42 
43 /* Statistical Check Miscellaneous */
44 #define TRNG_RTSCMISC		    0x0604
45 #define BM_TRNG_RTSCMISC_RTY_CNT    SHIFT_U32(0xF, 16)
46 #define TRNG_RTSCMISC_RTY_CNT(val)  SHIFT_U32(((val) & (0xF)), 16)
47 #define BM_TRNG_RTSCMISC_LRUN_MAX   SHIFT_U32(0xFF, 0)
48 #define TRNG_RTSCMISC_LRUN_MAX(val) SHIFT_U32(((val) & (0xFF)), 0)
49 
50 /* Poker Range */
51 #define TRNG_RTPKRRNG		   0x0608
52 #define BM_TRNG_RTPKRRNG_PKR_RNG   SHIFT_U32(0xFFFF, 0)
53 #define TRNG_RTPKRRNG_PKR_RNG(val) SHIFT_U32(((val) & (0xFFFF)), 0)
54 
55 /* Poker Maximum Limit */
56 #define TRNG_RTPKRMAX		   0x060C
57 #define BM_TRNG_RTPKRMAX_PKR_MAX   SHIFT_U32(0xFFFFFF, 0)
58 #define TRNG_RTPKRMAX_PKR_MAX(val) SHIFT_U32(((val) & (0xFFFFFF)), 0)
59 
60 /* Statistical Check Monobit Limit */
61 #define TRNG_RTSCML		  0x0620
62 #define BM_TRNG_RTSCML_MONO_RNG	  SHIFT_U32(0xFFFF, 16)
63 #define TRNG_RTSCML_MONO_RNG(val) SHIFT_U32(((val) & (0xFFFF)), 16)
64 #define BM_TRNG_RTSCML_MONO_MAX	  SHIFT_U32(0xFFFF, 0)
65 #define TRNG_RTSCML_MONO_MAX(val) SHIFT_U32(((val) & (0xFFFF)), 0)
66 
67 /* Statistical Check Run Length 1 Limit */
68 #define TRNG_RTSCR1L		   0x0624
69 #define BM_TRNG_RTSCR1L_RUN1_RNG   SHIFT_U32(0x7FFF, 16)
70 #define TRNG_RTSCR1L_RUN1_RNG(val) SHIFT_U32(((val) & (0x7FFF)), 16)
71 #define BM_TRNG_RTSCR1L_RUN1_MAX   SHIFT_U32(0x7FFF, 0)
72 #define TRNG_RTSCR1L_RUN1_MAX(val) SHIFT_U32(((val) & (0x7FFF)), 0)
73 
74 /* Statistical Check Run Length 2 Limit */
75 #define TRNG_RTSCR2L		   0x0628
76 #define BM_TRNG_RTSCR2L_RUN2_RNG   SHIFT_U32(0x3FFF, 16)
77 #define TRNG_RTSCR2L_RUN2_RNG(val) SHIFT_U32(((val) & (0x3FFF)), 16)
78 #define BM_TRNG_RTSCR2L_RUN2_MAX   SHIFT_U32(0x3FFF, 0)
79 #define TRNG_RTSCR2L_RUN2_MAX(val) SHIFT_U32(((val) & (0x3FFF)), 0)
80 
81 /* Statistical Check Run Length 3 Limit */
82 #define TRNG_RTSCR3L		   0x062C
83 #define BM_TRNG_RTSCR3L_RUN3_RNG   SHIFT_U32(0x1FFF, 16)
84 #define TRNG_RTSCR3L_RUN3_RNG(val) SHIFT_U32(((val) & (0x1FFF)), 16)
85 #define BM_TRNG_RTSCR3L_RUN3_MAX   SHIFT_U32(0x1FFF, 0)
86 #define TRNG_RTSCR3L_RUN3_MAX(val) SHIFT_U32(((val) & (0x1FFF)), 0)
87 
88 /* Statistical Check Run Length 4 Limit */
89 #define TRNG_RTSCR4L		   0x0630
90 #define BM_TRNG_RTSCR4L_RUN4_RNG   SHIFT_U32(0xFFF, 16)
91 #define TRNG_RTSCR4L_RUN4_RNG(val) SHIFT_U32(((val) & (0xFFF)), 16)
92 #define BM_TRNG_RTSCR4L_RUN4_MAX   SHIFT_U32(0xFFF, 0)
93 #define TRNG_RTSCR4L_RUN4_MAX(val) SHIFT_U32(((val) & (0xFFF)), 0)
94 
95 /* Statistical Check Run Length 5 Limit */
96 #define TRNG_RTSCR5L		   0x0634
97 #define BM_TRNG_RTSCR5L_RUN5_RNG   SHIFT_U32(0x7FF, 16)
98 #define TRNG_RTSCR5L_RUN5_RNG(val) SHIFT_U32(((val) & (0x7FF)), 16)
99 #define BM_TRNG_RTSCR5L_RUN5_MAX   SHIFT_U32(0x7FF, 0)
100 #define TRNG_RTSCR5L_RUN5_MAX(val) SHIFT_U32(((val) & (0x7FF)), 0)
101 
102 /* Statistical Check Run Length 6+ Limit */
103 #define TRNG_RTSCR6PL		     0x0638
104 #define BM_TRNG_RTSCR6PL_RUN6P_RNG   SHIFT_U32(0x7FF, 16)
105 #define TRNG_RTSCR6PL_RUN6P_RNG(val) SHIFT_U32(((val) & (0x7FF)), 16)
106 #define BM_TRNG_RTSCR6PL_RUN6P_MAX   SHIFT_U32(0x7FF, 0)
107 #define TRNG_RTSCR6PL_RUN6P_MAX(val) SHIFT_U32(((val) & (0x7FF)), 0)
108 
109 /*
110  * RNG Registers
111  */
112 /* Status */
113 #define RNG_STA				0x06C0
114 
115 #define RNG_STA_SKVN		BIT32(30)
116 #define RNG_STA_IF1			BIT32(1)
117 #define RNG_STA_IF0			BIT32(0)
118 
119 #endif /* __RNG_REGS_H__ */
120