From 490f07a78dd9e44b38096bd91d0e10676b41bded Mon Sep 17 00:00:00 2001 From: Juha Yrjola Date: Tue, 6 Sep 2005 16:08:08 +0300 Subject: [PATCH] [PATCH] ARM: OMAP: OMAP16xx RNG Minimal hardware RNG support for 16xx --- drivers/char/Kconfig | 12 ++++++ drivers/char/Makefile | 1 + drivers/char/omap16xx-rng.c | 75 +++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 drivers/char/omap16xx-rng.c diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index c1bf5f6022e..629e46e5e62 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -659,6 +659,18 @@ config HW_RANDOM If unsure, say N. +config OMAP16XX_RNG + tristate "OMAP16xx Random Number Generator support" + depends on ARCH_OMAP16XX + ---help--- + This driver provides kernel-side support for the Random Number + Generator hardware found on OMAP16xx multimedia processors. + + To compile this driver as a module, choose M here: the + module will be called hw_random. + + If unsure, say N. + config NVRAM tristate "/dev/nvram support" depends on ATARI || X86 || X86_64 || ARM || GENERIC_NVRAM diff --git a/drivers/char/Makefile b/drivers/char/Makefile index dc6db246e6c..d7d8df647db 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile @@ -75,6 +75,7 @@ obj-$(CONFIG_TOSHIBA) += toshiba.o obj-$(CONFIG_I8K) += i8k.o obj-$(CONFIG_DS1620) += ds1620.o obj-$(CONFIG_HW_RANDOM) += hw_random.o +obj-$(CONFIG_OMAP16XX_RNG) += omap16xx-rng.o obj-$(CONFIG_FTAPE) += ftape/ obj-$(CONFIG_COBALT_LCD) += lcd.o obj-$(CONFIG_PPDEV) += ppdev.o diff --git a/drivers/char/omap16xx-rng.c b/drivers/char/omap16xx-rng.c new file mode 100644 index 00000000000..0638eaacf90 --- /dev/null +++ b/drivers/char/omap16xx-rng.c @@ -0,0 +1,75 @@ +/* + * drivers/char/omap16xx-rng.c + * + * Copyright (C) 2005 Nokia Corporation + * Author: Juha Yrjölä + * + * OMAP16xx Random Number Generator driver + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include +#include + +#define RNG_BASE 0xfffe5000 +#define RNG_OUT_REG 0x00 +#define RNG_STAT_REG 0x04 +#define RNG_REV_REG 0x3c +#define RNG_MASK_REG 0x40 + +#define ENTROPY_WORD_COUNT 128 + +static u32 rng_base = io_p2v(RNG_BASE); + +static u32 rng_read_reg(int reg) +{ + return __raw_readl(rng_base + reg); +} + +static void rng_write_reg(int reg, u32 val) +{ + __raw_writel(val, rng_base + reg); +} + +static void rng_feed_entropy(int count) +{ + u32 l; + + while (count--) { + while (rng_read_reg(RNG_STAT_REG)); + l = rng_read_reg(RNG_OUT_REG); + add_input_randomness(0, 0, l); + } +} + +static int __init rng_init(void) +{ + if (!cpu_is_omap16xx()) + return -ENODEV; + + printk("OMAP16xx Random Number Generator ver. %02x\n", + rng_read_reg(RNG_REV_REG)); + rng_write_reg(RNG_MASK_REG, 0x00000001); + rng_feed_entropy(ENTROPY_WORD_COUNT); + rng_write_reg(RNG_MASK_REG, 0x00000000); + printk("%d words of entropy generated\n", ENTROPY_WORD_COUNT); + + return 0; +} + +static void __exit rng_cleanup(void) +{ +} + +MODULE_AUTHOR("Juha Yrjölä"); +MODULE_DESCRIPTION("OMAP16xx H/W Random Number Generator (RNG) driver"); +MODULE_LICENSE("GPL"); + +module_init(rng_init); +module_exit(rng_cleanup); -- 2.41.1