Linux Audio

Check our new training course

Loading...
v6.8
 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
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
46	if (!cpu_is_ixp46x()) /* includes IXP455 */
47		return -ENOSYS;
48
49	rng_base = devm_platform_ioremap_resource(pdev, 0);
50	if (IS_ERR(rng_base))
51		return PTR_ERR(rng_base);
52
53	ixp4xx_rng_ops.priv = (unsigned long)rng_base;
54	return devm_hwrng_register(dev, &ixp4xx_rng_ops);
 
 
 
 
55}
56
57static const struct of_device_id ixp4xx_rng_of_match[] = {
58	{
59		.compatible = "intel,ixp46x-rng",
60	},
61	{},
62};
63MODULE_DEVICE_TABLE(of, ixp4xx_rng_of_match);
64
65static 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};
72module_platform_driver(ixp4xx_rng_driver);
73
74MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
75MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x");
76MODULE_LICENSE("GPL");
v5.9
 
 1/*
 2 * drivers/char/hw_random/ixp4xx-rng.c
 3 *
 4 * RNG driver for Intel IXP4xx family of NPUs
 5 *
 6 * Author: Deepak Saxena <dsaxena@plexity.net>
 7 *
 8 * Copyright 2005 (c) MontaVista Software, Inc.
 9 *
10 * Fixes by Michael Buesch
11 *
12 * This file is licensed under  the terms of the GNU General Public
13 * License version 2. This program is licensed "as is" without any
14 * warranty of any kind, whether express or implied.
15 */
16
17#include <linux/kernel.h>
18#include <linux/types.h>
19#include <linux/module.h>
20#include <linux/moduleparam.h>
 
21#include <linux/init.h>
22#include <linux/bitops.h>
23#include <linux/hw_random.h>
 
 
24
25#include <asm/io.h>
26#include <mach/hardware.h>
27
28
29static int ixp4xx_rng_data_read(struct hwrng *rng, u32 *buffer)
30{
31	void __iomem * rng_base = (void __iomem *)rng->priv;
32
33	*buffer = __raw_readl(rng_base);
34
35	return 4;
36}
37
38static struct hwrng ixp4xx_rng_ops = {
39	.name		= "ixp4xx",
40	.data_read	= ixp4xx_rng_data_read,
41};
42
43static int __init ixp4xx_rng_init(void)
44{
45	void __iomem * rng_base;
46	int err;
47
48	if (!cpu_is_ixp46x()) /* includes IXP455 */
49		return -ENOSYS;
50
51	rng_base = ioremap(0x70002100, 4);
52	if (!rng_base)
53		return -ENOMEM;
 
54	ixp4xx_rng_ops.priv = (unsigned long)rng_base;
55	err = hwrng_register(&ixp4xx_rng_ops);
56	if (err)
57		iounmap(rng_base);
58
59	return err;
60}
61
62static void __exit ixp4xx_rng_exit(void)
63{
64	void __iomem * rng_base = (void __iomem *)ixp4xx_rng_ops.priv;
 
 
 
 
65
66	hwrng_unregister(&ixp4xx_rng_ops);
67	iounmap(rng_base);
68}
69
70module_init(ixp4xx_rng_init);
71module_exit(ixp4xx_rng_exit);
 
 
72
73MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
74MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x");
75MODULE_LICENSE("GPL");