esp32: drivers: Add Entropy Device tree support

- Add TRNG module to esp32.dtsi
- Updated the note about TRNG register address

Signed-off-by: Mohamed ElShahawi <ExtremeGTX@hotmail.com>
This commit is contained in:
Mohamed ElShahawi 2019-10-22 10:04:13 +02:00 committed by Kumar Gala
commit 55471982f6
6 changed files with 46 additions and 9 deletions

View file

@ -70,3 +70,7 @@
sda-pin = <18>;
scl-pin = <5>;
};
&trng0 {
status = "okay";
};

View file

@ -8,6 +8,7 @@ config ENTROPY_ESP32_RNG
bool "ESP32 entropy number generator driver"
depends on SOC_ESP32
select ENTROPY_HAS_DRIVER
select HAS_DTS_ENTROPY
help
This option enables the entropy number generator for ESP32 SoCs.

View file

@ -9,14 +9,15 @@
static inline u32_t entropy_esp32_get_u32(void)
{
/* The documentation specifies the random number generator at the
* following address, which is at odds with the SDK, that specifies
* it at 0x60035144. The fact that they're 0x200c0000 bytes apart
* (lower 16 bits are the same) suggests this might be the same
* register, just mirrored somewhere else in the address space.
* Confirmation is required.
/*
* APB Address: 0x60035144 (Safe,slower writes)
* DPORT Address: 0x3ff75144 (write bug, fast writes)
* In this case it won't make a difference because it is read only
* More info available at:
* https://www.esp32.com/viewtopic.php?f=2&t=3033&p=14227
* also check: ECO and Workarounds for Bugs Document, point 3.3
*/
volatile u32_t *rng_data_reg = (u32_t *)0x3ff75144;
volatile u32_t *rng_data_reg = (u32_t *)DT_INST_0_ESPRESSIF_ESP32_TRNG_BASE_ADDRESS;
/* Read just once. This is not optimal as the generator has
* limited throughput due to scarce sources of entropy, specially
@ -53,7 +54,7 @@ static struct entropy_driver_api entropy_esp32_api_funcs = {
.get_entropy = entropy_esp32_get_entropy
};
DEVICE_AND_API_INIT(entropy_esp32, CONFIG_ENTROPY_NAME,
DEVICE_AND_API_INIT(entropy_esp32, DT_INST_0_ESPRESSIF_ESP32_TRNG_LABEL,
entropy_esp32_init, NULL, NULL,
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&entropy_esp32_api_funcs);

View file

@ -0,0 +1,23 @@
# Copyright (c) 2019, Mohamed ElShahawi <ExtremeGTX@hotmail.com>
# SPDX-License-Identifier: Apache-2.0
title: Espressif ESP32 TRNG (True Random Number Generator)
description: >
The TRNG use the noise in the Wi-Fi/BT RF system.
When Wi-Fi and BT are disabled, the random number generator will give out
pseudo-random numbers.
compatible: "espressif,esp32-trng"
include: base.yaml
properties:
reg:
required: true
interrupts:
required: false
label:
required: true

View file

@ -92,5 +92,13 @@
label = "I2C_1";
status = "disabled";
};
trng0: trng@3ff75144 {
compatible = "espressif,esp32-trng";
reg = <0x3FF75144 0x4>;
/* interrupts = <33 0>; - FIXME: Enable interrupts when interrupt-controller got supported in device tree */
label = "TRNG_0";
status = "disabled";
};
};
};

View file

@ -7,5 +7,5 @@
/* SoC level DTS fixup file */
#define DT_CPU_CLOCK_FREQUENCY DT_CADENCE_TENSILICA_XTENSA_LX6_0_CLOCK_FREQUENCY
#define CONFIG_ENTROPY_NAME DT_INST_0_ESPRESSIF_ESP32_TRNG_LABEL
/* End of SoC Level DTS fixup file */