diff --git a/chip/g/build.mk b/chip/g/build.mk index 6b235ced4b..4450faf43a 100644 --- a/chip/g/build.mk +++ b/chip/g/build.mk @@ -25,6 +25,7 @@ else chip-y += uart.o endif chip-y+= pmu.o +chip-y+= trng.o chip-$(CONFIG_SPS)+= sps.o chip-$(CONFIG_HOSTCMD_SPS)+=sps_hc.o chip-$(CONFIG_TPM_SPS)+=sps_tpm.o diff --git a/chip/g/trng.c b/chip/g/trng.c new file mode 100644 index 0000000000..e462127da8 --- /dev/null +++ b/chip/g/trng.c @@ -0,0 +1,22 @@ +/* Copyright 2015 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "registers.h" + +void init_trng(void) +{ + GWRITE(TRNG, POWER_DOWN_B, 1); + GWRITE(TRNG, GO_EVENT, 1); + while (GREAD(TRNG, EMPTY)) + ; + GREAD(TRNG, READ_DATA); +} + +uint32_t rand(void) +{ + while (GREAD(TRNG, EMPTY)) + ; + return GREAD(TRNG, READ_DATA); +}