xref: /rk3399_rockchip-uboot/drivers/rng/rockchip_rand.c (revision f36ea2f6e17621c4d9dd97c4dbfab62d03d061df)
1 /*
2  * (C) Copyright 2021 Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 #include <common.h>
7 #include <dm.h>
8 #include <rng.h>
9 
10 unsigned int rand_r(unsigned int *seedp)
11 {
12 	struct udevice *dev;
13 	unsigned int rand;
14 	int ret;
15 
16 	ret = uclass_get_device(UCLASS_RNG, 0, &dev);
17 	if (ret) {
18 		printf("No RNG device, ret=%d\n", ret);
19 		return ret;
20 	}
21 
22 	ret = dm_rng_read(dev, &rand, sizeof(unsigned int));
23 	if (ret) {
24 		printf("Reading RNG failed, ret=%d\n", ret);
25 		return ret;
26 	}
27 
28 	return rand;
29 }
30 
31 unsigned int rand(void)
32 {
33 	return rand_r(0);
34 }
35 
36 void srand(unsigned int seed)
37 {
38 	/* nothing to do */
39 }
40 
41