Skip to content

Commit

Permalink
drivers: entropy: rv32m1_trng: Add DTS support to rv32m1_trng driver
Browse files Browse the repository at this point in the history
Add a YAML, DTS node and driver support to utilize data from devicetree
for register address and driver name.

Signed-off-by: Kumar Gala <[email protected]>
  • Loading branch information
galak authored and ioannisg committed Apr 2, 2020
1 parent 19965f8 commit 0be9d2b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions drivers/entropy/Kconfig.rv32m1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config ENTROPY_RV32M1_TRNG
bool "RV32M1 TRNG driver"
depends on SOC_OPENISA_RV32M1_RISCV32
select ENTROPY_HAS_DRIVER
select HAS_DTS_ENTROPY
help
This option enables the true random number generator (TRNG)
driver based on the RV32M1 TRNG driver.
Expand Down
6 changes: 4 additions & 2 deletions drivers/entropy/entropy_rv32m1_trng.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT openisa_rv32m1_trng

#include <device.h>
#include <drivers/entropy.h>
#include <random/rand32.h>
Expand Down Expand Up @@ -34,12 +36,12 @@ static const struct entropy_driver_api entropy_rv32m1_trng_api_funcs = {
};

static struct rv32m1_entropy_config entropy_rv32m1_config = {
.base = TRNG
.base = (TRNG_Type *)DT_INST_REG_ADDR(0)
};

static int entropy_rv32m1_trng_init(struct device *);

DEVICE_AND_API_INIT(entropy_rv32m1_trng, CONFIG_ENTROPY_NAME,
DEVICE_AND_API_INIT(entropy_rv32m1_trng, DT_INST_LABEL(0),
entropy_rv32m1_trng_init, NULL, &entropy_rv32m1_config,
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&entropy_rv32m1_trng_api_funcs);
Expand Down
18 changes: 18 additions & 0 deletions dts/bindings/rng/openisa,rv32m1-trng.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2020, Linaro Limited
# SPDX-License-Identifier: Apache-2.0

description: OpenISA TRNG (True Random Number Generator)

compatible: "openisa,rv32m1-trng"

include: base.yaml

properties:
reg:
required: true

interrupts:
required: true

label:
required: true
8 changes: 8 additions & 0 deletions dts/riscv/rv32m1.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,14 @@
#pwm-cells = <3>;
};

trng: random@41029000{
compatible = "openisa,rv32m1-trng";
reg = <0x41029000 0x1000>;
status = "okay";
interrupts = <13 0>;
label = "TRNG";
};

pwm3: pwm@4102d000 {
compatible = "openisa,rv32m1-tpm";
reg = <0x4102d000 0x88>;
Expand Down
5 changes: 5 additions & 0 deletions dts/riscv/rv32m1_ri5cy.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,8 @@
interrupt-parent = <&intmux0_ch1>;
interrupts = <23>;
};

&trng {
interrupt-parent = <&intmux0_ch1>;
interrupts = <20>;
};
5 changes: 5 additions & 0 deletions dts/riscv/rv32m1_zero_riscy.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,8 @@
interrupt-parent = <&event1>;
interrupts = <15>;
};

&trng {
interrupt-parent = <&event1>;
interrupts = <12>;
};
1 change: 1 addition & 0 deletions soc/riscv/openisa_rv32m1/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define DT_FLASH_DEV_BASE_ADDRESS DT_OPENISA_RV32M1_FTFE_40023000_BASE_ADDRESS
#define DT_FLASH_DEV_NAME DT_OPENISA_RV32M1_FTFE_40023000_LABEL
#define DT_START_UP_ENTRY_OFFSET 0x80
#define CONFIG_ENTROPY_NAME DT_LABEL(DT_INST(0, openisa_rv32m1_trng))

#endif /* CONFIG_SOC_OPENISA_RV32M1_RISCV32 */

Expand Down

0 comments on commit 0be9d2b

Please sign in to comment.