2021-05-11 18:08:40 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2006-06-26 15:25:02 +08:00
|
|
|
/*
|
2006-10-04 05:01:26 +08:00
|
|
|
* drivers/char/hw_random/ixp4xx-rng.c
|
2006-06-26 15:25:02 +08:00
|
|
|
*
|
|
|
|
* RNG driver for Intel IXP4xx family of NPUs
|
|
|
|
*
|
|
|
|
* Author: Deepak Saxena <dsaxena@plexity.net>
|
|
|
|
*
|
|
|
|
* Copyright 2005 (c) MontaVista Software, Inc.
|
|
|
|
*
|
|
|
|
* Fixes by Michael Buesch
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
2021-05-11 20:15:42 +08:00
|
|
|
#include <linux/platform_device.h>
|
2006-06-26 15:25:02 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/hw_random.h>
|
2021-05-11 21:04:21 +08:00
|
|
|
#include <linux/of.h>
|
2019-08-26 04:20:54 +08:00
|
|
|
#include <linux/soc/ixp4xx/cpu.h>
|
2006-06-26 15:25:02 +08:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
static int ixp4xx_rng_data_read(struct hwrng *rng, u32 *buffer)
|
|
|
|
{
|
|
|
|
void __iomem * rng_base = (void __iomem *)rng->priv;
|
|
|
|
|
|
|
|
*buffer = __raw_readl(rng_base);
|
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct hwrng ixp4xx_rng_ops = {
|
|
|
|
.name = "ixp4xx",
|
|
|
|
.data_read = ixp4xx_rng_data_read,
|
|
|
|
};
|
|
|
|
|
2021-05-11 20:15:42 +08:00
|
|
|
static int ixp4xx_rng_probe(struct platform_device *pdev)
|
2006-06-26 15:25:02 +08:00
|
|
|
{
|
|
|
|
void __iomem * rng_base;
|
2021-05-11 20:15:42 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2006-06-26 15:25:02 +08:00
|
|
|
|
2010-03-24 03:22:13 +08:00
|
|
|
if (!cpu_is_ixp46x()) /* includes IXP455 */
|
|
|
|
return -ENOSYS;
|
|
|
|
|
2021-09-07 15:40:41 +08:00
|
|
|
rng_base = devm_platform_ioremap_resource(pdev, 0);
|
2021-05-11 20:15:42 +08:00
|
|
|
if (IS_ERR(rng_base))
|
|
|
|
return PTR_ERR(rng_base);
|
2006-06-26 15:25:02 +08:00
|
|
|
|
2021-05-11 20:15:42 +08:00
|
|
|
ixp4xx_rng_ops.priv = (unsigned long)rng_base;
|
|
|
|
return devm_hwrng_register(dev, &ixp4xx_rng_ops);
|
2006-06-26 15:25:02 +08:00
|
|
|
}
|
|
|
|
|
2021-05-11 21:04:21 +08:00
|
|
|
static const struct of_device_id ixp4xx_rng_of_match[] = {
|
|
|
|
{
|
|
|
|
.compatible = "intel,ixp46x-rng",
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, ixp4xx_rng_of_match);
|
|
|
|
|
2021-05-11 20:15:42 +08:00
|
|
|
static struct platform_driver ixp4xx_rng_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ixp4xx-hwrandom",
|
2021-05-11 21:04:21 +08:00
|
|
|
.of_match_table = ixp4xx_rng_of_match,
|
2021-05-11 20:15:42 +08:00
|
|
|
},
|
|
|
|
.probe = ixp4xx_rng_probe,
|
|
|
|
};
|
|
|
|
module_platform_driver(ixp4xx_rng_driver);
|
2006-06-26 15:25:02 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
|
2010-03-24 03:22:13 +08:00
|
|
|
MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x");
|
2006-06-26 15:25:02 +08:00
|
|
|
MODULE_LICENSE("GPL");
|