xref: /OK3568_Linux_fs/u-boot/drivers/rng/rockchip_rand.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 
rand_r(unsigned int * seedp)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 
rand(void)31 unsigned int rand(void)
32 {
33 	return rand_r(0);
34 }
35 
srand(unsigned int seed)36 void srand(unsigned int seed)
37 {
38 	/* nothing to do */
39 }
40 
41