WIP FPC-III support
[linux/fpc-iii.git] / drivers / char / hw_random / powernv-rng.c
blob8da1d7917bdc45d78f2b0afef6c69cd31a6c2746
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright 2013 Michael Ellerman, Guo Chao, IBM Corp.
4 */
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <linux/module.h>
9 #include <linux/mod_devicetable.h>
10 #include <linux/kernel.h>
11 #include <linux/platform_device.h>
12 #include <linux/random.h>
13 #include <linux/hw_random.h>
15 static int powernv_rng_read(struct hwrng *rng, void *data, size_t max, bool wait)
17 unsigned long *buf;
18 int i, len;
20 /* We rely on rng_buffer_size() being >= sizeof(unsigned long) */
21 len = max / sizeof(unsigned long);
23 buf = (unsigned long *)data;
25 for (i = 0; i < len; i++)
26 powernv_get_random_long(buf++);
28 return len * sizeof(unsigned long);
31 static struct hwrng powernv_hwrng = {
32 .name = "powernv-rng",
33 .read = powernv_rng_read,
36 static int powernv_rng_probe(struct platform_device *pdev)
38 int rc;
40 rc = devm_hwrng_register(&pdev->dev, &powernv_hwrng);
41 if (rc) {
42 /* We only register one device, ignore any others */
43 if (rc == -EEXIST)
44 rc = -ENODEV;
46 return rc;
49 pr_info("Registered powernv hwrng.\n");
51 return 0;
54 static const struct of_device_id powernv_rng_match[] = {
55 { .compatible = "ibm,power-rng",},
56 {},
58 MODULE_DEVICE_TABLE(of, powernv_rng_match);
60 static struct platform_driver powernv_rng_driver = {
61 .driver = {
62 .name = "powernv_rng",
63 .of_match_table = powernv_rng_match,
65 .probe = powernv_rng_probe,
67 module_platform_driver(powernv_rng_driver);
69 MODULE_LICENSE("GPL");
70 MODULE_DESCRIPTION("Bare metal HWRNG driver for POWER7+ and above");