23
23
#include <linux/platform_device.h>
24
24
#include <linux/pm_runtime.h>
25
25
26
- #define EXYNOS_TRNG_CLKDIV (0x0)
27
-
28
- #define EXYNOS_TRNG_CTRL (0x20)
29
- #define EXYNOS_TRNG_CTRL_RNGEN BIT(31)
30
-
31
- #define EXYNOS_TRNG_POST_CTRL (0x30)
32
- #define EXYNOS_TRNG_ONLINE_CTRL (0x40)
33
- #define EXYNOS_TRNG_ONLINE_STAT (0x44)
34
- #define EXYNOS_TRNG_ONLINE_MAXCHI2 (0x48)
35
- #define EXYNOS_TRNG_FIFO_CTRL (0x50)
36
- #define EXYNOS_TRNG_FIFO_0 (0x80)
37
- #define EXYNOS_TRNG_FIFO_1 (0x84)
38
- #define EXYNOS_TRNG_FIFO_2 (0x88)
39
- #define EXYNOS_TRNG_FIFO_3 (0x8c)
40
- #define EXYNOS_TRNG_FIFO_4 (0x90)
41
- #define EXYNOS_TRNG_FIFO_5 (0x94)
42
- #define EXYNOS_TRNG_FIFO_6 (0x98)
43
- #define EXYNOS_TRNG_FIFO_7 (0x9c)
44
- #define EXYNOS_TRNG_FIFO_LEN (8)
45
- #define EXYNOS_TRNG_CLOCK_RATE (500000)
46
-
26
+ #define EXYNOS_TRNG_CLKDIV 0x0
27
+
28
+ #define EXYNOS_TRNG_CTRL 0x20
29
+ #define EXYNOS_TRNG_CTRL_RNGEN BIT(31)
30
+
31
+ #define EXYNOS_TRNG_POST_CTRL 0x30
32
+ #define EXYNOS_TRNG_ONLINE_CTRL 0x40
33
+ #define EXYNOS_TRNG_ONLINE_STAT 0x44
34
+ #define EXYNOS_TRNG_ONLINE_MAXCHI2 0x48
35
+ #define EXYNOS_TRNG_FIFO_CTRL 0x50
36
+ #define EXYNOS_TRNG_FIFO_0 0x80
37
+ #define EXYNOS_TRNG_FIFO_1 0x84
38
+ #define EXYNOS_TRNG_FIFO_2 0x88
39
+ #define EXYNOS_TRNG_FIFO_3 0x8c
40
+ #define EXYNOS_TRNG_FIFO_4 0x90
41
+ #define EXYNOS_TRNG_FIFO_5 0x94
42
+ #define EXYNOS_TRNG_FIFO_6 0x98
43
+ #define EXYNOS_TRNG_FIFO_7 0x9c
44
+ #define EXYNOS_TRNG_FIFO_LEN 8
45
+ #define EXYNOS_TRNG_CLOCK_RATE 500000
47
46
48
47
struct exynos_trng_dev {
49
- struct device * dev ;
50
- void __iomem * mem ;
51
- struct clk * clk ;
52
- struct hwrng rng ;
48
+ struct device * dev ;
49
+ void __iomem * mem ;
50
+ struct clk * clk ;
51
+ struct hwrng rng ;
53
52
};
54
53
55
54
static int exynos_trng_do_read (struct hwrng * rng , void * data , size_t max ,
56
55
bool wait )
57
56
{
58
- struct exynos_trng_dev * trng ;
57
+ struct exynos_trng_dev * trng = ( struct exynos_trng_dev * ) rng -> priv ;
59
58
int val ;
60
59
61
60
max = min_t (size_t , max , (EXYNOS_TRNG_FIFO_LEN * 4 ));
62
-
63
- trng = (struct exynos_trng_dev * )rng -> priv ;
64
-
65
61
writel_relaxed (max * 8 , trng -> mem + EXYNOS_TRNG_FIFO_CTRL );
66
62
val = readl_poll_timeout (trng -> mem + EXYNOS_TRNG_FIFO_CTRL , val ,
67
63
val == 0 , 200 , 1000000 );
@@ -87,7 +83,7 @@ static int exynos_trng_init(struct hwrng *rng)
87
83
*/
88
84
val = sss_rate / (EXYNOS_TRNG_CLOCK_RATE * 2 );
89
85
if (val > 0x7fff ) {
90
- dev_err (trng -> dev , "clock divider too large: %d" , val );
86
+ dev_err (trng -> dev , "clock divider too large: %d\n " , val );
91
87
return - ERANGE ;
92
88
}
93
89
val = val << 1 ;
@@ -122,7 +118,7 @@ static int exynos_trng_probe(struct platform_device *pdev)
122
118
123
119
trng -> rng .init = exynos_trng_init ;
124
120
trng -> rng .read = exynos_trng_do_read ;
125
- trng -> rng .priv = (unsigned long ) trng ;
121
+ trng -> rng .priv = (unsigned long )trng ;
126
122
127
123
platform_set_drvdata (pdev , trng );
128
124
trng -> dev = & pdev -> dev ;
@@ -175,7 +171,7 @@ static int exynos_trng_probe(struct platform_device *pdev)
175
171
176
172
static void exynos_trng_remove (struct platform_device * pdev )
177
173
{
178
- struct exynos_trng_dev * trng = platform_get_drvdata (pdev );
174
+ struct exynos_trng_dev * trng = platform_get_drvdata (pdev );
179
175
180
176
clk_disable_unprepare (trng -> clk );
181
177
@@ -204,7 +200,7 @@ static int exynos_trng_resume(struct device *dev)
204
200
}
205
201
206
202
static DEFINE_SIMPLE_DEV_PM_OPS (exynos_trng_pm_ops , exynos_trng_suspend ,
207
- exynos_trng_resume ) ;
203
+ exynos_trng_resume ) ;
208
204
209
205
static const struct of_device_id exynos_trng_dt_match [] = {
210
206
{
@@ -225,6 +221,7 @@ static struct platform_driver exynos_trng_driver = {
225
221
};
226
222
227
223
module_platform_driver (exynos_trng_driver );
224
+
228
225
MODULE_AUTHOR ("Łukasz Stelmach" );
229
226
MODULE_DESCRIPTION ("H/W TRNG driver for Exynos chips" );
230
227
MODULE_LICENSE ("GPL v2" );
0 commit comments