-
Notifications
You must be signed in to change notification settings - Fork 8.1k
drivers: misc: ethos_u: Add support NPU on Renesas devices #97530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
khoa-nguyen-18
wants to merge
3
commits into
zephyrproject-rtos:main
Choose a base branch
from
renesas:support_renesas_ra_npu
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+159
−1
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,99 @@ | ||||||||||
/* | ||||||||||
* Copyright (c) 2025 Renesas Electronics Corporation | ||||||||||
* | ||||||||||
* SPDX-License-Identifier: Apache-2.0 | ||||||||||
*/ | ||||||||||
|
||||||||||
#include <zephyr/irq.h> | ||||||||||
#include <zephyr/init.h> | ||||||||||
#include <zephyr/device.h> | ||||||||||
#include <zephyr/devicetree.h> | ||||||||||
#include <zephyr/logging/log.h> | ||||||||||
#include <ethosu_driver.h> | ||||||||||
#include <soc.h> | ||||||||||
|
||||||||||
#include "ethos_u_common.h" | ||||||||||
|
||||||||||
#define DT_DRV_COMPAT renesas_ra_npu | ||||||||||
LOG_MODULE_REGISTER(renesas_ra_npu, CONFIG_ETHOS_U_LOG_LEVEL); | ||||||||||
|
||||||||||
void ethos_u_renesas_ra_irq_handler(const struct device *dev) | ||||||||||
{ | ||||||||||
struct ethosu_data *data = dev->data; | ||||||||||
struct ethosu_driver *drv = &data->drv; | ||||||||||
IRQn_Type irq = R_FSP_CurrentIrqGet(); | ||||||||||
|
||||||||||
ethosu_irq_handler(drv); | ||||||||||
|
||||||||||
R_BSP_IrqStatusClear(irq); | ||||||||||
} | ||||||||||
|
||||||||||
static int ethos_u_renesas_ra_init(const struct device *dev) | ||||||||||
{ | ||||||||||
const struct ethosu_dts_info *config = dev->config; | ||||||||||
struct ethosu_data *data = dev->data; | ||||||||||
struct ethosu_driver *drv = &data->drv; | ||||||||||
struct ethosu_driver_version version; | ||||||||||
|
||||||||||
LOG_DBG("Ethos-U DTS info. base_address=0x%p, secure_enable=%u, privilege_enable=%u", | ||||||||||
config->base_addr, config->secure_enable, config->privilege_enable); | ||||||||||
|
||||||||||
ethosu_get_driver_version(&version); | ||||||||||
|
||||||||||
LOG_DBG("Version. major=%u, minor=%u, patch=%u", version.major, version.minor, | ||||||||||
version.patch); | ||||||||||
|
||||||||||
/* Turn on NPU power domain */ | ||||||||||
R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_OM_LPC_BATT); | ||||||||||
FSP_HARDWARE_REGISTER_WAIT( | ||||||||||
(R_SYSTEM->PDCTRNPU & (R_SYSTEM_PDCTRGD_PDCSF_Msk | R_SYSTEM_PDCTRGD_PDPGSF_Msk)), | ||||||||||
R_SYSTEM_PDCTRGD_PDPGSF_Msk); | ||||||||||
|
||||||||||
R_SYSTEM->PDCTRNPU = 0; | ||||||||||
|
||||||||||
FSP_HARDWARE_REGISTER_WAIT( | ||||||||||
(R_SYSTEM->PDCTRNPU & (R_SYSTEM_PDCTRGD_PDCSF_Msk | R_SYSTEM_PDCTRGD_PDPGSF_Msk)), | ||||||||||
0); | ||||||||||
R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_OM_LPC_BATT); | ||||||||||
|
||||||||||
R_BSP_MODULE_START(FSP_IP_NPU, 0); | ||||||||||
|
||||||||||
if (ethosu_init(drv, config->base_addr, NULL, 0, config->secure_enable, | ||||||||||
config->privilege_enable)) { | ||||||||||
LOG_ERR("Failed to initialize NPU with ethosu_init()."); | ||||||||||
return -EINVAL; | ||||||||||
} | ||||||||||
|
||||||||||
config->irq_config(); | ||||||||||
|
||||||||||
return 0; | ||||||||||
} | ||||||||||
|
||||||||||
#define ETHOSU_RENESAS_RA_DEVICE_INIT(idx) \ | ||||||||||
static struct ethosu_data ethosu_data_##idx; \ | ||||||||||
\ | ||||||||||
static void ethosu_zephyr_irq_config_##idx(void) \ | ||||||||||
{ \ | ||||||||||
R_ICU->IELSR_b[DT_INST_IRQ_BY_NAME(idx, npu_irq, irq)].IELS = \ | ||||||||||
BSP_PRV_IELS_ENUM(CONCAT(EVENT_NPU_IRQ)); \ | ||||||||||
Comment on lines
+77
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it change?
Suggested change
|
||||||||||
\ | ||||||||||
BSP_ASSIGN_EVENT_TO_CURRENT_CORE(BSP_PRV_IELS_ENUM(CONCAT(EVENT_NPU_IRQ))); \ | ||||||||||
\ | ||||||||||
IRQ_CONNECT(DT_INST_IRQN(idx), DT_INST_IRQ(idx, priority), \ | ||||||||||
ethos_u_renesas_ra_irq_handler, DEVICE_DT_INST_GET(idx), 0); \ | ||||||||||
\ | ||||||||||
irq_enable(DT_INST_IRQN(idx)); \ | ||||||||||
} \ | ||||||||||
\ | ||||||||||
static const struct ethosu_dts_info ethosu_dts_info_##idx = { \ | ||||||||||
.base_addr = (void *)DT_INST_REG_ADDR(idx), \ | ||||||||||
.secure_enable = DT_INST_PROP(idx, secure_enable), \ | ||||||||||
.privilege_enable = DT_INST_PROP(idx, privilege_enable), \ | ||||||||||
.irq_config = ðosu_zephyr_irq_config_##idx, \ | ||||||||||
}; \ | ||||||||||
\ | ||||||||||
DEVICE_DT_INST_DEFINE(idx, ethos_u_renesas_ra_init, NULL, ðosu_data_##idx, \ | ||||||||||
ðosu_dts_info_##idx, POST_KERNEL, \ | ||||||||||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); | ||||||||||
|
||||||||||
DT_INST_FOREACH_STATUS_OKAY(ETHOSU_RENESAS_RA_DEVICE_INIT); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) 2025 Renesas Electronics Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
description: Renesas RA frontend of Arm Ethos-U NPU driver | ||
|
||
compatible: "renesas,ra-npu" | ||
|
||
include: "arm,ethos-u.yaml" | ||
|
||
properties: | ||
interrupt-names: | ||
required: true | ||
enum: | ||
- "npu-irq" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
samples/modules/tflite-micro/tflm_ethosu/boards/ek_ra8p1_r7ka8p1kflcac_cm33.overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright (c) 2025 Renesas Electronics Corporation | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&npu0 { | ||
interrupts = <95 1>; | ||
interrupt-names = "npu-irq"; | ||
status = "okay"; | ||
}; |
10 changes: 10 additions & 0 deletions
10
samples/modules/tflite-micro/tflm_ethosu/boards/ek_ra8p1_r7ka8p1kflcac_cm85.overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright (c) 2025 Renesas Electronics Corporation | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&npu0 { | ||
interrupts = <95 1>; | ||
interrupt-names = "npu-irq"; | ||
status = "okay"; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be moved to SoC?