aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/char/hw_random/Kconfig13
-rw-r--r--drivers/char/hw_random/Makefile1
-rw-r--r--drivers/char/hw_random/omap3-rom-rng.c141
3 files changed, 155 insertions, 0 deletions
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 0aa9d91daef5..0a331c341fff 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -165,6 +165,19 @@ config HW_RANDOM_OMAP
165 165
166 If unsure, say Y. 166 If unsure, say Y.
167 167
168config HW_RANDOM_OMAP3_ROM
169 tristate "OMAP3 ROM Random Number Generator support"
170 depends on HW_RANDOM && ARCH_OMAP3
171 default HW_RANDOM
172 ---help---
173 This driver provides kernel-side support for the Random Number
174 Generator hardware found on OMAP34xx processors.
175
176 To compile this driver as a module, choose M here: the
177 module will be called omap3-rom-rng.
178
179 If unsure, say Y.
180
168config HW_RANDOM_OCTEON 181config HW_RANDOM_OCTEON
169 tristate "Octeon Random Number Generator support" 182 tristate "Octeon Random Number Generator support"
170 depends on HW_RANDOM && CAVIUM_OCTEON_SOC 183 depends on HW_RANDOM && CAVIUM_OCTEON_SOC
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index bed467c9300e..7c8aa8077f5e 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -15,6 +15,7 @@ n2-rng-y := n2-drv.o n2-asm.o
15obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o 15obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o
16obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o 16obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
17obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o 17obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
18obj-$(CONFIG_HW_RANDOM_OMAP3_ROM) += omap3-rom-rng.o
18obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o 19obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
19obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o 20obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
20obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o 21obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
new file mode 100644
index 000000000000..c853e9e68573
--- /dev/null
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -0,0 +1,141 @@
1/*
2 * omap3-rom-rng.c - RNG driver for TI OMAP3 CPU family
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Juha Yrjola <juha.yrjola@solidboot.com>
6 *
7 * Copyright (C) 2013 Pali Rohár <pali.rohar@gmail.com>
8 *
9 * This file is licensed under the terms of the GNU General Public
10 * License version 2. This program is licensed "as is" without any
11 * warranty of any kind, whether express or implied.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/random.h>
19#include <linux/hw_random.h>
20#include <linux/timer.h>
21#include <linux/clk.h>
22#include <linux/err.h>
23#include <linux/platform_device.h>
24
25#define RNG_RESET 0x01
26#define RNG_GEN_PRNG_HW_INIT 0x02
27#define RNG_GEN_HW 0x08
28
29/* param1: ptr, param2: count, param3: flag */
30static u32 (*omap3_rom_rng_call)(u32, u32, u32);
31
32static struct timer_list idle_timer;
33static int rng_idle;
34static struct clk *rng_clk;
35
36static void omap3_rom_rng_idle(unsigned long data)
37{
38 int r;
39
40 r = omap3_rom_rng_call(0, 0, RNG_RESET);
41 if (r != 0) {
42 pr_err("reset failed: %d\n", r);
43 return;
44 }
45 clk_disable_unprepare(rng_clk);
46 rng_idle = 1;
47}
48
49static int omap3_rom_rng_get_random(void *buf, unsigned int count)
50{
51 u32 r;
52 u32 ptr;
53
54 del_timer_sync(&idle_timer);
55 if (rng_idle) {
56 clk_prepare_enable(rng_clk);
57 r = omap3_rom_rng_call(0, 0, RNG_GEN_PRNG_HW_INIT);
58 if (r != 0) {
59 clk_disable_unprepare(rng_clk);
60 pr_err("HW init failed: %d\n", r);
61 return -EIO;
62 }
63 rng_idle = 0;
64 }
65
66 ptr = virt_to_phys(buf);
67 r = omap3_rom_rng_call(ptr, count, RNG_GEN_HW);
68 mod_timer(&idle_timer, jiffies + msecs_to_jiffies(500));
69 if (r != 0)
70 return -EINVAL;
71 return 0;
72}
73
74static int omap3_rom_rng_data_present(struct hwrng *rng, int wait)
75{
76 return 1;
77}
78
79static int omap3_rom_rng_data_read(struct hwrng *rng, u32 *data)
80{
81 int r;
82
83 r = omap3_rom_rng_get_random(data, 4);
84 if (r < 0)
85 return r;
86 return 4;
87}
88
89static struct hwrng omap3_rom_rng_ops = {
90 .name = "omap3-rom",
91 .data_present = omap3_rom_rng_data_present,
92 .data_read = omap3_rom_rng_data_read,
93};
94
95static int omap3_rom_rng_probe(struct platform_device *pdev)
96{
97 pr_info("initializing\n");
98
99 omap3_rom_rng_call = pdev->dev.platform_data;
100 if (!omap3_rom_rng_call) {
101 pr_err("omap3_rom_rng_call is NULL\n");
102 return -EINVAL;
103 }
104
105 setup_timer(&idle_timer, omap3_rom_rng_idle, 0);
106 rng_clk = clk_get(&pdev->dev, "ick");
107 if (IS_ERR(rng_clk)) {
108 pr_err("unable to get RNG clock\n");
109 return PTR_ERR(rng_clk);
110 }
111
112 /* Leave the RNG in reset state. */
113 clk_prepare_enable(rng_clk);
114 omap3_rom_rng_idle(0);
115
116 return hwrng_register(&omap3_rom_rng_ops);
117}
118
119static int omap3_rom_rng_remove(struct platform_device *pdev)
120{
121 hwrng_unregister(&omap3_rom_rng_ops);
122 clk_disable_unprepare(rng_clk);
123 clk_put(rng_clk);
124 return 0;
125}
126
127static struct platform_driver omap3_rom_rng_driver = {
128 .driver = {
129 .name = "omap3-rom-rng",
130 .owner = THIS_MODULE,
131 },
132 .probe = omap3_rom_rng_probe,
133 .remove = omap3_rom_rng_remove,
134};
135
136module_platform_driver(omap3_rom_rng_driver);
137
138MODULE_ALIAS("platform:omap3-rom-rng");
139MODULE_AUTHOR("Juha Yrjola");
140MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
141MODULE_LICENSE("GPL");