]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/char/omap-rng.c
ARM: OMAP: Really fix compile warning in uncompress.h
[linux-2.6-omap-h63xx.git] / drivers / char / omap-rng.c
1 /*
2  * drivers/char/omap-rng.c
3  *
4  * Copyright (C) 2005 Nokia Corporation
5  * Author: Juha Yrjölä <juha.yrjola@nokia.com>
6  *
7  * OMAP16xx and OMAP24xx Random Number Generator driver
8  *
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.
12  *
13  */
14
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/random.h>
18 #include <linux/err.h>
19
20 #include <asm/io.h>
21 #include <asm/hardware/clock.h>
22
23 #if defined (CONFIG_ARCH_OMAP16XX)
24 #define RNG_BASE        0xfffe5000
25 #endif
26 #if defined (CONFIG_ARCH_OMAP24XX)
27 #define RNG_BASE        0x480A0000
28 #endif
29 #define RNG_OUT_REG     0x00
30 #define RNG_STAT_REG    0x04
31 #define RNG_REV_REG     0x3c
32 #define RNG_MASK_REG    0x40
33
34 #define ENTROPY_WORD_COUNT 128
35
36 static u32 rng_base = io_p2v(RNG_BASE);
37
38 static struct clk *rng_ick = NULL;
39
40 static u32 rng_read_reg(int reg)
41 {
42         return __raw_readl(rng_base + reg);
43 }
44
45 static void rng_write_reg(int reg, u32 val)
46 {
47         __raw_writel(val, rng_base + reg);
48 }
49
50 static void rng_feed_entropy(int count)
51 {
52         u32 l;
53
54         while (count--) {
55                 while (rng_read_reg(RNG_STAT_REG));
56                 l = rng_read_reg(RNG_OUT_REG);
57                 add_input_randomness(0, 0, l);
58         }
59 }
60
61 static int __init rng_init(void)
62 {
63         if (!cpu_is_omap16xx() && !cpu_is_omap24xx())
64                 return -ENODEV;
65
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);
71                 }
72                 clk_use(rng_ick);
73         }
74
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);
81
82         return 0;
83 }
84 late_initcall(rng_init);