rng: rockchip: add hardware rand library
Signed-off-by: Joseph Chen <chenjh@rock-chips.com> Change-Id: Id22c5725158d86cc8a2ff80fdf09b0146d04be41
This commit is contained in:
parent
6126937122
commit
3f0522ce8f
|
|
@ -5,3 +5,8 @@
|
||||||
|
|
||||||
obj-$(CONFIG_DM_RNG) += rng-uclass.o
|
obj-$(CONFIG_DM_RNG) += rng-uclass.o
|
||||||
obj-$(CONFIG_RNG_ROCKCHIP) += rockchip_rng.o
|
obj-$(CONFIG_RNG_ROCKCHIP) += rockchip_rng.o
|
||||||
|
|
||||||
|
ifdef CONFIG_LIB_HW_RAND
|
||||||
|
obj-$(CONFIG_RNG_ROCKCHIP) += rockchip_rand.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* (C) Copyright 2021 Rockchip Electronics Co., Ltd
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0+
|
||||||
|
*/
|
||||||
|
#include <common.h>
|
||||||
|
#include <dm.h>
|
||||||
|
#include <rng.h>
|
||||||
|
|
||||||
|
unsigned int rand_r(unsigned int *seedp)
|
||||||
|
{
|
||||||
|
struct udevice *dev;
|
||||||
|
unsigned int rand;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = uclass_get_device(UCLASS_RNG, 0, &dev);
|
||||||
|
if (ret) {
|
||||||
|
printf("No RNG device, ret=%d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = dm_rng_read(dev, &rand, sizeof(unsigned int));
|
||||||
|
if (ret) {
|
||||||
|
printf("Reading RNG failed, ret=%d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rand;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int rand(void)
|
||||||
|
{
|
||||||
|
return rand_r(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void srand(unsigned int seed)
|
||||||
|
{
|
||||||
|
/* nothing to do */
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue