2 * drivers/char/omap-rng.c
4 * Copyright (C) 2005 Nokia Corporation
5 * Author: Juha Yrjölä <juha.yrjola@nokia.com>
7 * OMAP16xx and OMAP24xx Random Number Generator driver
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/random.h>
18 #include <linux/err.h>
21 #include <asm/hardware/clock.h>
23 #if defined (CONFIG_ARCH_OMAP16XX)
24 #define RNG_BASE 0xfffe5000
26 #if defined (CONFIG_ARCH_OMAP24XX)
27 #define RNG_BASE 0x480A0000
29 #define RNG_OUT_REG 0x00
30 #define RNG_STAT_REG 0x04
31 #define RNG_REV_REG 0x3c
32 #define RNG_MASK_REG 0x40
34 #define ENTROPY_WORD_COUNT 128
36 static u32 rng_base = io_p2v(RNG_BASE);
38 static struct clk *rng_ick = NULL;
40 static u32 rng_read_reg(int reg)
42 return __raw_readl(rng_base + reg);
45 static void rng_write_reg(int reg, u32 val)
47 __raw_writel(val, rng_base + reg);
50 static void rng_feed_entropy(int count)
55 while (rng_read_reg(RNG_STAT_REG));
56 l = rng_read_reg(RNG_OUT_REG);
57 add_input_randomness(0, 0, l);
61 static int __init rng_init(void)
63 if (!cpu_is_omap16xx() && !cpu_is_omap24xx())
66 if (cpu_is_omap24xx()) {
67 rng_ick = clk_get(NULL, "rng_ick");
68 if (IS_ERR(rng_ick)) {
69 printk(KERN_ERR "omap-rng.c: Could not get rng_ick\n");
70 return PTR_ERR(rng_ick);
75 printk("OMAP Random Number Generator ver. %02x\n",
76 rng_read_reg(RNG_REV_REG));
77 rng_write_reg(RNG_MASK_REG, 0x00000001);
78 rng_feed_entropy(ENTROPY_WORD_COUNT);
79 rng_write_reg(RNG_MASK_REG, 0x00000000);
80 printk("%d words of entropy generated\n", ENTROPY_WORD_COUNT);
84 late_initcall(rng_init);