1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/kernel.h>
15#include <linux/types.h>
16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/platform_device.h>
19#include <linux/init.h>
20#include <linux/bitops.h>
21#include <linux/hw_random.h>
22#include <linux/of.h>
23#include <linux/soc/ixp4xx/cpu.h>
24
25#include <asm/io.h>
26
27static int ixp4xx_rng_data_read(struct hwrng *rng, u32 *buffer)
28{
29 void __iomem * rng_base = (void __iomem *)rng->priv;
30
31 *buffer = __raw_readl(rng_base);
32
33 return 4;
34}
35
36static struct hwrng ixp4xx_rng_ops = {
37 .name = "ixp4xx",
38 .data_read = ixp4xx_rng_data_read,
39};
40
41static int ixp4xx_rng_probe(struct platform_device *pdev)
42{
43 void __iomem * rng_base;
44 struct device *dev = &pdev->dev;
45 struct resource *res;
46
47 if (!cpu_is_ixp46x())
48 return -ENOSYS;
49
50 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
51 rng_base = devm_ioremap_resource(dev, res);
52 if (IS_ERR(rng_base))
53 return PTR_ERR(rng_base);
54
55 ixp4xx_rng_ops.priv = (unsigned long)rng_base;
56 return devm_hwrng_register(dev, &ixp4xx_rng_ops);
57}
58
59static const struct of_device_id ixp4xx_rng_of_match[] = {
60 {
61 .compatible = "intel,ixp46x-rng",
62 },
63 {},
64};
65MODULE_DEVICE_TABLE(of, ixp4xx_rng_of_match);
66
67static struct platform_driver ixp4xx_rng_driver = {
68 .driver = {
69 .name = "ixp4xx-hwrandom",
70 .of_match_table = ixp4xx_rng_of_match,
71 },
72 .probe = ixp4xx_rng_probe,
73};
74module_platform_driver(ixp4xx_rng_driver);
75
76MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
77MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x");
78MODULE_LICENSE("GPL");
79