2 * Hardware Random Number Generator support for Cavium Networks
3 * Octeon processor family.
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
9 * Copyright (C) 2009 Cavium Networks
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/device.h>
15 #include <linux/hw_random.h>
17 #include <linux/gfp.h>
19 #include <asm/octeon/octeon.h>
20 #include <asm/octeon/cvmx-rnm-defs.h>
24 void __iomem
*control_status
;
28 static int octeon_rng_init(struct hwrng
*rng
)
30 union cvmx_rnm_ctl_status ctl
;
31 struct octeon_rng
*p
= container_of(rng
, struct octeon_rng
, ops
);
34 ctl
.s
.ent_en
= 1; /* Enable the entropy source. */
35 ctl
.s
.rng_en
= 1; /* Enable the RNG hardware. */
36 cvmx_write_csr((u64
)p
->control_status
, ctl
.u64
);
40 static void octeon_rng_cleanup(struct hwrng
*rng
)
42 union cvmx_rnm_ctl_status ctl
;
43 struct octeon_rng
*p
= container_of(rng
, struct octeon_rng
, ops
);
46 /* Disable everything. */
47 cvmx_write_csr((u64
)p
->control_status
, ctl
.u64
);
50 static int octeon_rng_data_read(struct hwrng
*rng
, u32
*data
)
52 struct octeon_rng
*p
= container_of(rng
, struct octeon_rng
, ops
);
54 *data
= cvmx_read64_uint32((u64
)p
->result
);
58 static int octeon_rng_probe(struct platform_device
*pdev
)
60 struct resource
*res_ports
;
61 struct resource
*res_result
;
62 struct octeon_rng
*rng
;
66 .init
= octeon_rng_init
,
67 .cleanup
= octeon_rng_cleanup
,
68 .data_read
= octeon_rng_data_read
71 rng
= devm_kzalloc(&pdev
->dev
, sizeof(*rng
), GFP_KERNEL
);
75 res_ports
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
79 res_result
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
84 rng
->control_status
= devm_ioremap(&pdev
->dev
,
87 if (!rng
->control_status
)
90 rng
->result
= devm_ioremap(&pdev
->dev
,
98 platform_set_drvdata(pdev
, &rng
->ops
);
99 ret
= devm_hwrng_register(&pdev
->dev
, &rng
->ops
);
103 dev_info(&pdev
->dev
, "Octeon Random Number Generator\n");
108 static struct platform_driver octeon_rng_driver
= {
110 .name
= "octeon_rng",
112 .probe
= octeon_rng_probe
,
115 module_platform_driver(octeon_rng_driver
);
117 MODULE_AUTHOR("David Daney");
118 MODULE_LICENSE("GPL");