Skip to content

Commit fe17a10

Browse files
drivers: misc: ethos_u: Add support NPU on Renesas devices
Add support NPU driver on Renesas devices Signed-off-by: Khoa Nguyen <[email protected]>
1 parent 30cdbd3 commit fe17a10

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

drivers/misc/ethos_u/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ zephyr_library()
66
zephyr_library_sources(ethos_u_common.c)
77
zephyr_library_sources_ifdef(CONFIG_ETHOS_U_ARM ethos_u_arm.c)
88
zephyr_library_sources_ifdef(CONFIG_ETHOS_U_NUMAKER ethos_u_numaker.c)
9+
zephyr_library_sources_ifdef(CONFIG_ETHOS_U_RENESAS ethos_u_renesas.c)

drivers/misc/ethos_u/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ choice
66
depends on ETHOS_U
77
default ETHOS_U_ARM if DT_HAS_ARM_ETHOS_U_ENABLED
88
default ETHOS_U_NUMAKER if DT_HAS_NUVOTON_NUMAKER_NPU_ENABLED
9+
default ETHOS_U_RENESAS if DT_HAS_RENESAS_RA_NPU_ENABLED
910

1011
config ETHOS_U_ARM
1112
bool "Arm Ethos-U NPU driver"
@@ -17,6 +18,11 @@ config ETHOS_U_NUMAKER
1718
help
1819
Enables Nuvoton NuMaker frontend of Arm Ethos-U NPU driver
1920

21+
config ETHOS_U_RENESAS
22+
bool "Renesas RA Ethos-U NPU driver"
23+
help
24+
Enables Renesas RA frontend of Arm Ethos-U NPU driver.
25+
2026
endchoice
2127

2228
config ETHOS_U_DCACHE
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/irq.h>
8+
#include <zephyr/init.h>
9+
#include <zephyr/device.h>
10+
#include <zephyr/devicetree.h>
11+
#include <zephyr/logging/log.h>
12+
#include <ethosu_driver.h>
13+
#include <zephyr/drivers/clock_control/renesas_ra_cgc.h>
14+
#include <soc.h>
15+
16+
#include "ethos_u_common.h"
17+
18+
#define DT_DRV_COMPAT renesas_ra_npu
19+
LOG_MODULE_REGISTER(renesas_ra_npu, CONFIG_ETHOS_U_LOG_LEVEL);
20+
21+
struct ethos_u_renesas_config {
22+
const struct ethosu_dts_info ethosu_dts_info;
23+
const struct device *clock_dev;
24+
const struct clock_control_ra_subsys_cfg clock_subsys;
25+
};
26+
27+
void ethos_u_renesas_ra_irq_handler(const struct device *dev)
28+
{
29+
struct ethosu_data *data = dev->data;
30+
struct ethosu_driver *drv = &data->drv;
31+
IRQn_Type irq = R_FSP_CurrentIrqGet();
32+
33+
ethosu_irq_handler(drv);
34+
35+
R_BSP_IrqStatusClear(irq);
36+
}
37+
38+
static int ethos_u_renesas_ra_init(const struct device *dev)
39+
{
40+
const struct ethos_u_renesas_config *config = dev->config;
41+
const struct ethosu_dts_info ethosu_dts_info = config->ethosu_dts_info;
42+
struct ethosu_data *data = dev->data;
43+
struct ethosu_driver *drv = &data->drv;
44+
struct ethosu_driver_version version;
45+
int err;
46+
47+
if (!device_is_ready(config->clock_dev)) {
48+
LOG_ERR("clock control device not ready");
49+
return -ENODEV;
50+
}
51+
52+
err = clock_control_on(config->clock_dev, (clock_control_subsys_t)&config->clock_subsys);
53+
if (err < 0) {
54+
LOG_ERR("Could not initialize clock (%d)", err);
55+
return err;
56+
}
57+
58+
if ((((0 == R_SYSTEM->PGCSAR_b.NONSEC2) && FSP_PRIV_TZ_USE_SECURE_REGS) ||
59+
((1 == R_SYSTEM->PGCSAR_b.NONSEC2) && BSP_TZ_NONSECURE_BUILD)) &&
60+
(0 != R_SYSTEM->PDCTRNPU)) {
61+
/* Turn on NPU power domain */
62+
R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_OM_LPC_BATT);
63+
FSP_HARDWARE_REGISTER_WAIT((R_SYSTEM->PDCTRNPU & (R_SYSTEM_PDCTRNPU_PDCSF_Msk |
64+
R_SYSTEM_PDCTRGD_PDPGSF_Msk)),
65+
R_SYSTEM_PDCTRGD_PDPGSF_Msk);
66+
R_SYSTEM->PDCTRNPU = 0;
67+
FSP_HARDWARE_REGISTER_WAIT((R_SYSTEM->PDCTRNPU & (R_SYSTEM_PDCTRNPU_PDCSF_Msk |
68+
R_SYSTEM_PDCTRGD_PDPGSF_Msk)),
69+
0);
70+
R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_OM_LPC_BATT);
71+
}
72+
73+
LOG_DBG("Ethos-U DTS info. base_address=0x%p, secure_enable=%u, privilege_enable=%u",
74+
ethosu_dts_info.base_addr, ethosu_dts_info.secure_enable,
75+
ethosu_dts_info.privilege_enable);
76+
77+
ethosu_get_driver_version(&version);
78+
79+
LOG_DBG("Version. major=%u, minor=%u, patch=%u", version.major, version.minor,
80+
version.patch);
81+
82+
if (ethosu_init(drv, ethosu_dts_info.base_addr, NULL, 0, ethosu_dts_info.secure_enable,
83+
ethosu_dts_info.privilege_enable)) {
84+
LOG_ERR("Failed to initialize NPU with ethosu_init().");
85+
return -EINVAL;
86+
}
87+
88+
ethosu_dts_info.irq_config();
89+
90+
return 0;
91+
}
92+
93+
#define ETHOSU_RENESAS_RA_DEVICE_INIT(idx) \
94+
static struct ethosu_data ethosu_data_##idx; \
95+
\
96+
static void ethosu_zephyr_irq_config_##idx(void) \
97+
{ \
98+
R_ICU->IELSR_b[DT_INST_IRQ_BY_NAME(idx, npu_irq, irq)].IELS = \
99+
BSP_PRV_IELS_ENUM(EVENT_NPU_IRQ); \
100+
\
101+
BSP_ASSIGN_EVENT_TO_CURRENT_CORE(BSP_PRV_IELS_ENUM(EVENT_NPU_IRQ)); \
102+
\
103+
IRQ_CONNECT(DT_INST_IRQN(idx), DT_INST_IRQ(idx, priority), \
104+
ethos_u_renesas_ra_irq_handler, DEVICE_DT_INST_GET(idx), 0); \
105+
\
106+
irq_enable(DT_INST_IRQN(idx)); \
107+
} \
108+
\
109+
static const struct ethos_u_renesas_config ethos_u_renesas_config##idx = { \
110+
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \
111+
.clock_subsys = \
112+
{ \
113+
.mstp = (uint32_t)DT_INST_CLOCKS_CELL_BY_IDX(idx, 0, mstp), \
114+
.stop_bit = DT_INST_CLOCKS_CELL_BY_IDX(idx, 0, stop_bit), \
115+
}, \
116+
.ethosu_dts_info = \
117+
{ \
118+
.base_addr = (void *)DT_INST_REG_ADDR(idx), \
119+
.secure_enable = DT_INST_PROP(idx, secure_enable), \
120+
.privilege_enable = DT_INST_PROP(idx, privilege_enable), \
121+
.irq_config = &ethosu_zephyr_irq_config_##idx, \
122+
}, \
123+
}; \
124+
\
125+
DEVICE_DT_INST_DEFINE(idx, ethos_u_renesas_ra_init, NULL, &ethosu_data_##idx, \
126+
&ethos_u_renesas_config##idx, POST_KERNEL, \
127+
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);
128+
129+
DT_INST_FOREACH_STATUS_OKAY(ETHOSU_RENESAS_RA_DEVICE_INIT);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2025 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Renesas RA frontend of Arm Ethos-U NPU driver
5+
6+
compatible: "renesas,ra-npu"
7+
8+
include: "arm,ethos-u.yaml"
9+
10+
properties:
11+
clocks:
12+
required: true
13+
14+
interrupt-names:
15+
required: true
16+
enum:
17+
- "npu-irq"

0 commit comments

Comments
 (0)