2323#include <linux/platform_device.h>
2424#include <linux/pm_runtime.h>
2525
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
4746
4847struct 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 ;
5352};
5453
5554static int exynos_trng_do_read (struct hwrng * rng , void * data , size_t max ,
5655 bool wait )
5756{
58- struct exynos_trng_dev * trng ;
57+ struct exynos_trng_dev * trng = ( struct exynos_trng_dev * ) rng -> priv ;
5958 int val ;
6059
6160 max = min_t (size_t , max , (EXYNOS_TRNG_FIFO_LEN * 4 ));
62-
63- trng = (struct exynos_trng_dev * )rng -> priv ;
64-
6561 writel_relaxed (max * 8 , trng -> mem + EXYNOS_TRNG_FIFO_CTRL );
6662 val = readl_poll_timeout (trng -> mem + EXYNOS_TRNG_FIFO_CTRL , val ,
6763 val == 0 , 200 , 1000000 );
@@ -87,7 +83,7 @@ static int exynos_trng_init(struct hwrng *rng)
8783 */
8884 val = sss_rate / (EXYNOS_TRNG_CLOCK_RATE * 2 );
8985 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 );
9187 return - ERANGE ;
9288 }
9389 val = val << 1 ;
@@ -122,7 +118,7 @@ static int exynos_trng_probe(struct platform_device *pdev)
122118
123119 trng -> rng .init = exynos_trng_init ;
124120 trng -> rng .read = exynos_trng_do_read ;
125- trng -> rng .priv = (unsigned long ) trng ;
121+ trng -> rng .priv = (unsigned long )trng ;
126122
127123 platform_set_drvdata (pdev , trng );
128124 trng -> dev = & pdev -> dev ;
@@ -175,7 +171,7 @@ static int exynos_trng_probe(struct platform_device *pdev)
175171
176172static void exynos_trng_remove (struct platform_device * pdev )
177173{
178- struct exynos_trng_dev * trng = platform_get_drvdata (pdev );
174+ struct exynos_trng_dev * trng = platform_get_drvdata (pdev );
179175
180176 clk_disable_unprepare (trng -> clk );
181177
@@ -204,7 +200,7 @@ static int exynos_trng_resume(struct device *dev)
204200}
205201
206202static DEFINE_SIMPLE_DEV_PM_OPS (exynos_trng_pm_ops , exynos_trng_suspend ,
207- exynos_trng_resume ) ;
203+ exynos_trng_resume ) ;
208204
209205static const struct of_device_id exynos_trng_dt_match [] = {
210206 {
@@ -225,6 +221,7 @@ static struct platform_driver exynos_trng_driver = {
225221};
226222
227223module_platform_driver (exynos_trng_driver );
224+
228225MODULE_AUTHOR ("Łukasz Stelmach" );
229226MODULE_DESCRIPTION ("H/W TRNG driver for Exynos chips" );
230227MODULE_LICENSE ("GPL v2" );
0 commit comments