Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / char / hw_random / powernv-rng.c
blob47b88de029f2deec8c84be3d6c5af3aa413f8dee
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>
14 #include <asm/archrandom.h>
16 static int powernv_rng_read(struct hwrng *rng, void *data, size_t max, bool wait)
18 unsigned long *buf;
19 int i, len;
21 /* We rely on rng_buffer_size() being >= sizeof(unsigned long) */
22 len = max / sizeof(unsigned long);
24 buf = (unsigned long *)data;
26 for (i = 0; i < len; i++)
27 pnv_get_random_long(buf++);
29 return len * sizeof(unsigned long);
32 static struct hwrng powernv_hwrng = {
33 .name = "powernv-rng",
34 .read = powernv_rng_read,
37 static int powernv_rng_probe(struct platform_device *pdev)
39 int rc;
41 rc = devm_hwrng_register(&pdev->dev, &powernv_hwrng);
42 if (rc) {
43 /* We only register one device, ignore any others */
44 if (rc == -EEXIST)
45 rc = -ENODEV;
47 return rc;
50 pr_info("Registered powernv hwrng.\n");
52 return 0;
55 static const struct of_device_id powernv_rng_match[] = {
56 { .compatible = "ibm,power-rng",},
57 {},
59 MODULE_DEVICE_TABLE(of, powernv_rng_match);
61 static struct platform_driver powernv_rng_driver = {
62 .driver = {
63 .name = "powernv_rng",
64 .of_match_table = powernv_rng_match,
66 .probe = powernv_rng_probe,
68 module_platform_driver(powernv_rng_driver);
70 MODULE_LICENSE("GPL");
71 MODULE_DESCRIPTION("Bare metal HWRNG driver for POWER7+ and above");