Skip to content

Commit 65760af

Browse files
drivers: entropy: Introduce driver for SiWx917
Support for random number generator is required for most of the cryptographic operations, including support for WiFi and TLS. This driver has been tested with tests/drivers/entropy: *** Booting Zephyr OS build v3.7.0-4339-g1ec5ce05f9f8 *** Running TESTSUITE entropy_api =================================================================== START - test_entropy_get_entropy random device is 0x8217298, name is rng@45090000 0x93 0x3e 0xf1 0x68 0xd4 0x22 0xbf 0x4d 0xad PASS - test_entropy_get_entropy in 0.012 seconds =================================================================== TESTSUITE entropy_api succeeded ------ TESTSUITE SUMMARY START ------ SUITE PASS - 100.00% [entropy_api]: pass = 1, fail = 0, skip = 0 ... - PASS - [entropy_api.test_entropy_get_entropy] duration = 0.01 ... ------ TESTSUITE SUMMARY END ------ =================================================================== RunID: d1547c805699201af769cb01331efcce PROJECT EXECUTION SUCCESSFUL Co-authored-by: Tibor Laczko <[email protected]> Signed-off-by: Tibor Laczko <[email protected]> Signed-off-by: Jérôme Pouiller <[email protected]>
1 parent 582dea6 commit 65760af

File tree

8 files changed

+108
-1
lines changed

8 files changed

+108
-1
lines changed

drivers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
add_subdirectory(bluetooth)
5+
add_subdirectory(entropy)
56
add_subdirectory(gpio)
67
add_subdirectory(pinctrl)
78
add_subdirectory(wifi)

drivers/entropy/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2024 Silicon Laboratories Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
zephyr_library_amend()
5+
zephyr_library_sources_ifdef(CONFIG_ENTROPY_SILABS_SIWX917 entropy_silabs_siwx917.c)

drivers/entropy/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2024 Silicon Laboratories Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if ENTROPY_GENERATOR
5+
6+
rsource "Kconfig.siwx917"
7+
8+
endif

drivers/entropy/Kconfig.siwx917

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2024 Silicon Laboratories Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config ENTROPY_SILABS_SIWX917
5+
bool "SiWx917 RNG driver"
6+
default y
7+
depends on DT_HAS_SILABS_SIWX917_RNG_ENABLED
8+
select ENTROPY_HAS_DRIVER
9+
help
10+
Enable hardware Random Number Generator embedded on Silicon Labs
11+
SiWx917 chips.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2024 Silicon Laboratories Inc.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
#define DT_DRV_COMPAT silabs_siwx917_rng
6+
7+
#include <zephyr/drivers/entropy.h>
8+
9+
#include "rsi_rom_rng.h"
10+
#include "rsi_rom_clks.h"
11+
12+
static int siwx917_get_entropy_isr(const struct device *dev, uint8_t *buffer,
13+
uint16_t length, uint32_t flags)
14+
{
15+
uint32_t u32_count = length / sizeof(uint32_t);
16+
uint32_t u8_count = u32_count * sizeof(uint32_t);
17+
uint32_t u8_remainder = length - u8_count;
18+
uint32_t swap_space;
19+
20+
if (!(flags & ENTROPY_BUSYWAIT)) {
21+
return -ENOTSUP;
22+
}
23+
RSI_RNG_GetBytes((void *)dev->config, (uint32_t *)buffer, u32_count);
24+
if (length % sizeof(uint32_t)) {
25+
RSI_RNG_GetBytes((void *)dev->config, &swap_space, 1);
26+
memcpy(buffer + u8_count, &swap_space, u8_remainder);
27+
}
28+
29+
return 0;
30+
}
31+
32+
static int siwx917_get_entropy(const struct device *dev, uint8_t *buffer, uint16_t length)
33+
{
34+
return siwx917_get_entropy_isr(dev, buffer, length, ENTROPY_BUSYWAIT);
35+
}
36+
37+
static int siwx917_init(const struct device *dev)
38+
{
39+
int ret;
40+
41+
ret = RSI_CLK_PeripheralClkEnable1(M4CLK, HWRNG_PCLK_ENABLE);
42+
if (ret) {
43+
return -EIO;
44+
}
45+
ret = RSI_RNG_Start((void *)dev->config, RSI_RNG_TRUE_RANDOM);
46+
if (ret) {
47+
return -EIO;
48+
}
49+
return 0;
50+
}
51+
52+
static const struct entropy_driver_api siwx917_api = {
53+
.get_entropy = siwx917_get_entropy,
54+
.get_entropy_isr = siwx917_get_entropy_isr,
55+
};
56+
57+
#define SIWX917_RNG_INIT(idx) \
58+
DEVICE_DT_INST_DEFINE(idx, siwx917_init, NULL, NULL, (void *)DT_INST_REG_ADDR(idx), \
59+
PRE_KERNEL_1, CONFIG_ENTROPY_INIT_PRIORITY, &siwx917_api);
60+
61+
DT_INST_FOREACH_STATUS_OKAY(SIWX917_RNG_INIT)

dts/arm/silabs/siwg917.dtsi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include <zephyr/dt-bindings/spi/spi.h>
1010

1111
/ {
12+
chosen {
13+
zephyr,entropy = &rng0;
14+
};
15+
1216
cpus {
1317
#address-cells = <1>;
1418
#size-cells = <0>;
@@ -202,6 +206,11 @@
202206
interrupt-names = "i2c2";
203207
status = "disabled";
204208
};
209+
210+
rng0: rng@45090000 {
211+
compatible = "silabs,siwx917-rng";
212+
reg = <0x45090000 0x8>;
213+
};
205214
};
206215
};
207216

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2024 Silicon Laboratories Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Hardware Random Number Generator embedded on Silabs SiWx917 chips
5+
6+
compatible: "silabs,siwx917-rng"
7+
8+
include: base.yaml
9+
10+
properties:
11+
reg:
12+
required: true

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ manifest:
1111
projects:
1212
- name: hal_silabs
1313
remote: silabs
14-
revision: 2eb82930b376900f1b6949e218199ab33ba6f34c
14+
revision: ca720524a33c4bb55446ceb7e94502e37153d941
1515
path: modules/hal/silabs
1616
- name: zephyr
1717
remote: zephyrproject-rtos

0 commit comments

Comments
 (0)