-
Notifications
You must be signed in to change notification settings - Fork 7.6k
drivers: misc: ethos_u: support nuvoton numaker m55m1x #88941
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
base: main
Are you sure you want to change the base?
Changes from all commits
f4d62cd
c1e9697
8a6e096
9d85e18
f1e3831
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Copyright (c) 2025 Nuvoton Technology Corporation. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#define DT_DRV_COMPAT nuvoton_numaker_npu | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zephyr/drivers/clock_control.h> | ||
#include <zephyr/drivers/clock_control/clock_control_numaker.h> | ||
#include <zephyr/drivers/reset.h> | ||
|
||
#include <ethosu_driver.h> | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(ethos_u_numaker, CONFIG_ETHOS_U_LOG_LEVEL); | ||
|
||
#include <soc.h> | ||
|
||
struct ethos_u_numaker_config { | ||
void *base_addr; | ||
const struct device *clkctrl_dev; | ||
struct numaker_scc_subsys pcc; | ||
struct reset_dt_spec reset; | ||
void (*irq_config)(const struct device *dev); | ||
bool secure_enable; | ||
bool privilege_enable; | ||
uint8_t flush_mask; | ||
uint8_t invalidate_mask; | ||
}; | ||
|
||
struct ethos_u_numaker_data { | ||
struct ethosu_driver drv; | ||
}; | ||
|
||
static void ethos_u_numaker_irq_handler(const struct device *dev) | ||
{ | ||
struct ethos_u_numaker_data *data = dev->data; | ||
struct ethosu_driver *drv = &data->drv; | ||
|
||
ethosu_irq_handler(drv); | ||
} | ||
|
||
static int ethos_u_numaker_init(const struct device *dev) | ||
{ | ||
const struct ethos_u_numaker_config *config = dev->config; | ||
struct ethos_u_numaker_data *data = dev->data; | ||
struct ethosu_driver *drv = &data->drv; | ||
int rc; | ||
|
||
/* Invoke Clock controller to enable module clock */ | ||
|
||
/* Equivalent to CLK_EnableModuleClock() */ | ||
rc = clock_control_on(config->clkctrl_dev, (clock_control_subsys_t)&config->pcc); | ||
if (rc < 0) { | ||
return rc; | ||
} | ||
rc = clock_control_on(config->clkctrl_dev, (clock_control_subsys_t)&config->pcc); | ||
if (rc < 0) { | ||
return rc; | ||
} | ||
|
||
/* Equivalent to CLK_SetModuleClock() */ | ||
rc = clock_control_configure(config->clkctrl_dev, (clock_control_subsys_t)&config->pcc, | ||
NULL); | ||
if (rc < 0) { | ||
return rc; | ||
} | ||
|
||
/* Invoke Reset controller to reset module to default state */ | ||
/* Equivalent to SYS_ResetModule() */ | ||
rc = reset_line_toggle_dt(&config->reset); | ||
if (rc < 0) { | ||
return rc; | ||
} | ||
|
||
LOG_DBG("Ethos-U DTS info: base_addr=0x%p, secure_enable=%u, privilege_enable=%u", | ||
config->base_addr, config->secure_enable, config->privilege_enable); | ||
|
||
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; | ||
} | ||
|
||
ethosu_set_basep_cache_mask(drv, config->flush_mask, config->invalidate_mask); | ||
|
||
config->irq_config(dev); | ||
|
||
return 0; | ||
} | ||
|
||
/* Peripheral Clock Control */ | ||
#define NUMAKER_PCC_INST_GET(inst) \ | ||
{ \ | ||
.subsys_id = NUMAKER_SCC_SUBSYS_ID_PCC, \ | ||
.pcc.clk_modidx = DT_INST_CLOCKS_CELL(inst, clock_module_index), \ | ||
.pcc.clk_src = DT_INST_CLOCKS_CELL(inst, clock_source), \ | ||
.pcc.clk_div = DT_INST_CLOCKS_CELL(inst, clock_divider), \ | ||
} | ||
|
||
#define NUMAKER_ETHOS_U_INIT(inst) \ | ||
static void ethos_u_numaker_irq_config_##inst(const struct device *dev) \ | ||
{ \ | ||
IRQ_CONNECT(DT_INST_IRQ(inst, irq), DT_INST_IRQ(inst, priority), \ | ||
ethos_u_numaker_irq_handler, DEVICE_DT_INST_GET(inst), 0); \ | ||
\ | ||
irq_enable(DT_INST_IRQ(inst, irq)); \ | ||
} \ | ||
\ | ||
static const struct ethos_u_numaker_config ethos_u_numaker_config_##inst = { \ | ||
.base_addr = (void *)DT_INST_REG_ADDR(inst), \ | ||
.clkctrl_dev = DEVICE_DT_GET(DT_PARENT(DT_INST_CLOCKS_CTLR(inst))), \ | ||
.pcc = NUMAKER_PCC_INST_GET(inst), \ | ||
.reset = RESET_DT_SPEC_INST_GET(inst), \ | ||
.irq_config = ethos_u_numaker_irq_config_##inst, \ | ||
.secure_enable = DT_INST_PROP(inst, secure_enable), \ | ||
.privilege_enable = DT_INST_PROP(inst, privilege_enable), \ | ||
.flush_mask = DT_INST_PROP(inst, flush_mask), \ | ||
.invalidate_mask = DT_INST_PROP(inst, invalidate_mask), \ | ||
}; \ | ||
\ | ||
static struct ethos_u_numaker_data ethos_u_numaker_data_##inst; \ | ||
\ | ||
DEVICE_DT_INST_DEFINE(inst, ethos_u_numaker_init, NULL, ðos_u_numaker_data_##inst, \ | ||
ðos_u_numaker_config_##inst, POST_KERNEL, \ | ||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); | ||
|
||
DT_INST_FOREACH_STATUS_OKAY(NUMAKER_ETHOS_U_INIT); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright (c) 2025 Nuvoton Technology Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
description: Nuvoton NuMaker frontend of Arm Ethos-U NPU driver | ||
|
||
compatible: "nuvoton,numaker-npu" | ||
|
||
include: ["arm,ethos-u.yaml", reset-device.yaml] | ||
|
||
properties: | ||
reg: | ||
required: true | ||
|
||
interrupts: | ||
required: true | ||
|
||
resets: | ||
required: true | ||
|
||
clocks: | ||
required: true | ||
|
||
flush-mask: | ||
type: int | ||
default: 2 | ||
description: | | ||
Base pointer cache flush mask passed to ethos-u core driver | ||
ethosu_set_basep_cache_mask(). Default is to follow ethos-u | ||
core driver for scratch region. | ||
|
||
invalidate-mask: | ||
type: int | ||
default: 2 | ||
description: | | ||
Base pointer cache invalidation mask passed to ethos-u core driver | ||
ethosu_set_basep_cache_mask(). Default is to follow ethos-u | ||
core driver for scratch region. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -307,6 +307,19 @@ __weak void _exit(int status) | |
} | ||
} | ||
|
||
/* Address undefined _fini for the exit call | ||
* | ||
* With gcc command-line options -nostartfiles or -nostdlib, the gcc | ||
* built-in object files crti.o/crtn.o which implement _init/_fini | ||
* won't get linked in automatically and will cause undefined reference | ||
* to _fini error when exit is invoked. | ||
* | ||
* This is fixed by providing one dummey _fini to let linker pass. | ||
*/ | ||
__weak void _fini(void) | ||
{ | ||
} | ||
Comment on lines
+310
to
+321
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. 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. @ccli8 maybe I missed something but how is this change related to this PR? did you face this issue while running the new samples? 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. Yes. This sample |
||
|
||
#ifndef CONFIG_NEWLIB_LIBC_CUSTOM_SBRK | ||
void *_sbrk(intptr_t count) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
# Copyright 2022 Arm Limited and/or its affiliates <[email protected]> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config TFLM_ETHOSU_TAINT_BLOBS | ||
config TAINT_BLOBS_TFLM | ||
bool | ||
default y | ||
select TAINT_BLOBS | ||
|
||
config TAINT_BLOBS_TFLM_ETHOSU | ||
bool "Choose Vela-compiled model targeting Ethos-U" | ||
default y | ||
depends on TAINT_BLOBS_TFLM | ||
|
||
source "Kconfig.zephyr" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
&npu0 { | ||
status = "okay"; | ||
}; |
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.
the discussion here could influence this change so I would appreciate your feedback there.
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.
OK. Besides, this PR will update according to result of #90787.