19 #include <linux/module.h>
21 #include <linux/kernel.h>
31 #define RNGA_CONTROL 0x00
32 #define RNGA_STATUS 0x04
33 #define RNGA_ENTROPY 0x08
34 #define RNGA_OUTPUT_FIFO 0x0c
35 #define RNGA_MODE 0x10
36 #define RNGA_VERIFICATION_CONTROL 0x14
37 #define RNGA_OSC_CONTROL_COUNTER 0x18
38 #define RNGA_OSC1_COUNTER 0x1c
39 #define RNGA_OSC2_COUNTER 0x20
40 #define RNGA_OSC_COUNTER_STATUS 0x24
43 #define RNG_ADDR_RANGE 0x28
46 #define RNGA_CONTROL_SLEEP 0x00000010
47 #define RNGA_CONTROL_CLEAR_INT 0x00000008
48 #define RNGA_CONTROL_MASK_INTS 0x00000004
49 #define RNGA_CONTROL_HIGH_ASSURANCE 0x00000002
50 #define RNGA_CONTROL_GO 0x00000001
52 #define RNGA_STATUS_LEVEL_MASK 0x0000ff00
55 #define RNGA_STATUS_OSC_DEAD 0x80000000
56 #define RNGA_STATUS_SLEEP 0x00000010
57 #define RNGA_STATUS_ERROR_INT 0x00000008
58 #define RNGA_STATUS_FIFO_UNDERFLOW 0x00000004
59 #define RNGA_STATUS_LAST_READ_STATUS 0x00000002
60 #define RNGA_STATUS_SECURITY_VIOLATION 0x00000001
69 static int mxc_rnga_data_present(
struct hwrng *rng,
int wait)
74 for (i = 0; i < 20; i++) {
99 dev_dbg(mxc_rng->
dev,
"Error while reading random number!\n");
108 static int mxc_rnga_init(
struct hwrng *rng)
111 struct mxc_rng *mxc_rng =
container_of(rng,
struct mxc_rng, rng);
120 dev_err(mxc_rng->
dev,
"RNGA Oscillator is dead!\n");
131 static void mxc_rnga_cleanup(
struct hwrng *rng)
134 struct mxc_rng *mxc_rng =
container_of(rng,
struct mxc_rng, rng);
146 struct mxc_rng *mxc_rng;
153 mxc_rng->
dev = &pdev->
dev;
154 mxc_rng->
rng.name =
"mxc-rnga";
155 mxc_rng->
rng.init = mxc_rnga_init;
156 mxc_rng->
rng.cleanup = mxc_rnga_cleanup,
157 mxc_rng->
rng.data_present = mxc_rnga_data_present,
158 mxc_rng->
rng.data_read = mxc_rnga_data_read,
161 if (IS_ERR(mxc_rng->
clk)) {
162 dev_err(&pdev->
dev,
"Could not get rng_clk!\n");
163 err = PTR_ERR(mxc_rng->
clk);
167 clk_prepare_enable(mxc_rng->
clk);
189 dev_err(&pdev->
dev,
"MXC RNGA registering failed (%d)\n", err);
201 clk_disable_unprepare(mxc_rng->
clk);
210 struct mxc_rng *mxc_rng = platform_get_drvdata(pdev);
218 clk_disable_unprepare(mxc_rng->
clk);
228 .remove =
__exit_p(mxc_rnga_remove),
231 static int __init mod_init(
void)
236 static void __exit mod_exit(
void)