Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * drivers/char/hw_random/ixp4xx-rng.c
0004  *
0005  * RNG driver for Intel IXP4xx family of NPUs
0006  *
0007  * Author: Deepak Saxena <dsaxena@plexity.net>
0008  *
0009  * Copyright 2005 (c) MontaVista Software, Inc.
0010  *
0011  * Fixes by Michael Buesch
0012  */
0013 
0014 #include <linux/kernel.h>
0015 #include <linux/types.h>
0016 #include <linux/module.h>
0017 #include <linux/moduleparam.h>
0018 #include <linux/platform_device.h>
0019 #include <linux/init.h>
0020 #include <linux/bitops.h>
0021 #include <linux/hw_random.h>
0022 #include <linux/of.h>
0023 #include <linux/soc/ixp4xx/cpu.h>
0024 
0025 #include <asm/io.h>
0026 
0027 static int ixp4xx_rng_data_read(struct hwrng *rng, u32 *buffer)
0028 {
0029     void __iomem * rng_base = (void __iomem *)rng->priv;
0030 
0031     *buffer = __raw_readl(rng_base);
0032 
0033     return 4;
0034 }
0035 
0036 static struct hwrng ixp4xx_rng_ops = {
0037     .name       = "ixp4xx",
0038     .data_read  = ixp4xx_rng_data_read,
0039 };
0040 
0041 static int ixp4xx_rng_probe(struct platform_device *pdev)
0042 {
0043     void __iomem * rng_base;
0044     struct device *dev = &pdev->dev;
0045 
0046     if (!cpu_is_ixp46x()) /* includes IXP455 */
0047         return -ENOSYS;
0048 
0049     rng_base = devm_platform_ioremap_resource(pdev, 0);
0050     if (IS_ERR(rng_base))
0051         return PTR_ERR(rng_base);
0052 
0053     ixp4xx_rng_ops.priv = (unsigned long)rng_base;
0054     return devm_hwrng_register(dev, &ixp4xx_rng_ops);
0055 }
0056 
0057 static const struct of_device_id ixp4xx_rng_of_match[] = {
0058     {
0059         .compatible = "intel,ixp46x-rng",
0060     },
0061     {},
0062 };
0063 MODULE_DEVICE_TABLE(of, ixp4xx_rng_of_match);
0064 
0065 static struct platform_driver ixp4xx_rng_driver = {
0066     .driver = {
0067         .name = "ixp4xx-hwrandom",
0068         .of_match_table = ixp4xx_rng_of_match,
0069     },
0070     .probe = ixp4xx_rng_probe,
0071 };
0072 module_platform_driver(ixp4xx_rng_driver);
0073 
0074 MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
0075 MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x");
0076 MODULE_LICENSE("GPL");