1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* |
3 | * drivers/char/hw_random/ixp4xx-rng.c |
4 | * |
5 | * RNG driver for Intel IXP4xx family of NPUs |
6 | * |
7 | * Author: Deepak Saxena <dsaxena@plexity.net> |
8 | * |
9 | * Copyright 2005 (c) MontaVista Software, Inc. |
10 | * |
11 | * Fixes by Michael Buesch |
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 | |
27 | static 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(addr: rng_base); |
32 | |
33 | return 4; |
34 | } |
35 | |
36 | static struct hwrng ixp4xx_rng_ops = { |
37 | .name = "ixp4xx" , |
38 | .data_read = ixp4xx_rng_data_read, |
39 | }; |
40 | |
41 | static int ixp4xx_rng_probe(struct platform_device *pdev) |
42 | { |
43 | void __iomem * rng_base; |
44 | struct device *dev = &pdev->dev; |
45 | |
46 | if (!cpu_is_ixp46x()) /* includes IXP455 */ |
47 | return -ENOSYS; |
48 | |
49 | rng_base = devm_platform_ioremap_resource(pdev, index: 0); |
50 | if (IS_ERR(ptr: rng_base)) |
51 | return PTR_ERR(ptr: rng_base); |
52 | |
53 | ixp4xx_rng_ops.priv = (unsigned long)rng_base; |
54 | return devm_hwrng_register(dev, rng: &ixp4xx_rng_ops); |
55 | } |
56 | |
57 | static const struct of_device_id ixp4xx_rng_of_match[] = { |
58 | { |
59 | .compatible = "intel,ixp46x-rng" , |
60 | }, |
61 | {}, |
62 | }; |
63 | MODULE_DEVICE_TABLE(of, ixp4xx_rng_of_match); |
64 | |
65 | static struct platform_driver ixp4xx_rng_driver = { |
66 | .driver = { |
67 | .name = "ixp4xx-hwrandom" , |
68 | .of_match_table = ixp4xx_rng_of_match, |
69 | }, |
70 | .probe = ixp4xx_rng_probe, |
71 | }; |
72 | module_platform_driver(ixp4xx_rng_driver); |
73 | |
74 | MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>" ); |
75 | MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x" ); |
76 | MODULE_LICENSE("GPL" ); |
77 | |