drivers: misc: add Renesas RA ELC driver

Add support for the Renesas RA Event Link Controller, including
driver sources, Kconfig, and Devicetree bindings.

Signed-off-by: Khanh Nguyen <khanh.nguyen.wz@bp.renesas.com>
Signed-off-by: Khoa Nguyen <khoa.nguyen.xh@renesas.com>
This commit is contained in:
Khanh Nguyen 2025-03-28 13:39:18 +07:00 committed by Benjamin Cabé
commit ed757ca290
11 changed files with 282 additions and 0 deletions

View file

@ -14,3 +14,4 @@ add_subdirectory_ifdef(CONFIG_RENESAS_RA_EXTERNAL_INTERRUPT renesas_ra_external_
add_subdirectory_ifdef(CONFIG_NXP_RTXXX_DSP_CTRL nxp_rtxxx_dsp_ctrl)
add_subdirectory(coresight)
add_subdirectory(interconn)

View file

@ -15,6 +15,7 @@ source "drivers/misc/devmux/Kconfig"
source "drivers/misc/nordic_vpr_launcher/Kconfig"
source "drivers/misc/mcux_flexio/Kconfig"
source "drivers/misc/coresight/Kconfig"
source "drivers/misc/interconn/Kconfig"
source "drivers/misc/renesas_ra_external_interrupt/Kconfig"
source "drivers/misc/nxp_rtxxx_dsp_ctrl/Kconfig"

View file

@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
add_subdirectory_ifdef(CONFIG_RENESAS_ELC renesas_elc)

View file

@ -0,0 +1,10 @@
# Interconn drivers not exposing Zephyr Device Driver API
# Copyright (c) 2025 Renesas Electronics Corporation
# SPDX-License-Identifier: Apache-2.0
menu "Interconn Drivers"
source "drivers/misc/interconn/renesas_elc/Kconfig"
endmenu

View file

@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/drivers/misc/interconn/renesas_elc/renesas_elc.h)
zephyr_library()
zephyr_library_sources_ifdef(CONFIG_USERSPACE renesas_elc_handlers.c)
zephyr_library_sources_ifdef(CONFIG_RENESAS_RA_ELC renesas_ra_elc.c)

View file

@ -0,0 +1,22 @@
# Copyright (c) 2025 Renesas Electronics Corporation
# SPDX-License-Identifier: Apache-2.0
# Renesas Event Link Controller config options
menuconfig RENESAS_ELC
bool "Renesas Event Link Controller Driver"
depends on SOC_FAMILY_RENESAS_RA
help
Enable config options for Renesas Event Link Controller
if RENESAS_ELC
config RENESAS_ELC_INIT_PRIORITY
int "Renesas Event Link Controller initialization priority"
default KERNEL_INIT_PRIORITY_DEVICE
help
System initialization priority for Renesas Event Link Controller drivers.
source "drivers/misc/interconn/renesas_elc/Kconfig.renesas_ra_elc"
endif # RENESAS_ELC

View file

@ -0,0 +1,12 @@
# Copyright (c) 2025 Renesas Electronics Corporation
# SPDX-License-Identifier: Apache-2.0
# Renesas RA Event Link Controller Option
config RENESAS_RA_ELC
bool "Renesas RA Event Link Controller Driver"
depends on DT_HAS_RENESAS_RA_ELC_ENABLED
select USE_RA_FSP_ELC
default y
help
Enable config options for Renesas RA Event Link Controller

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2025 Renesas Electronics Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/drivers/misc/interconn/renesas_elc/renesas_elc.h>
#include <zephyr/syscall_handler.h>
int z_vrfy_renesas_elc_software_event_generate(const struct device *dev,
elc_software_event_t sw_event)
{
K_OOPS(K_SYSCALL_DRIVER_RENESAS_ELC(dev, software_event_generate));
return z_impl_renesas_elc_software_event_generate(dev, sw_event);
}
#include <zephyr/syscalls/renesas_elc_software_event_generate_mrsh.c>
int z_vrfy_renesas_elc_link_set(const struct device *dev, elc_peripheral_t peripheral,
elc_event_t event)
{
K_OOPS(K_SYSCALL_DRIVER_RENESAS_ELC(dev, link_set));
return z_impl_renesas_elc_link_set(dev, peripheral, event);
}
#include <zephyr/syscalls/renesas_elc_link_set_mrsh.c>
int z_vrfy_renesas_elc_link_break(const struct device *dev, elc_peripheral_t peripheral)
{
K_OOPS(K_SYSCALL_DRIVER_RENESAS_ELC(dev, link_break));
return z_impl_renesas_elc_link_break(dev, peripheral);
}
#include <zephyr/syscalls/renesas_elc_link_break_mrsh.c>
int z_vrfy_renesas_elc_enable(const struct device *dev)
{
K_OOPS(K_SYSCALL_DRIVER_RENESAS_ELC(dev, enable));
return z_impl_renesas_elc_enable(dev);
}
#include <zephyr/syscalls/renesas_elc_enable_mrsh.c>
int z_vrfy_renesas_elc_disable(const struct device *dev)
{
K_OOPS(K_SYSCALL_DRIVER_RENESAS_ELC(dev, disable));
return z_impl_renesas_elc_disable(dev);
}
#include <zephyr/syscalls/renesas_elc_disable_mrsh.c>

View file

@ -0,0 +1,151 @@
/*
* Copyright (c) 2025 Renesas Electronics Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT renesas_ra_elc
#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/util_macro.h>
#include <zephyr/drivers/misc/interconn/renesas_elc/renesas_elc.h>
#include <zephyr/drivers/clock_control/renesas_ra_cgc.h>
#include <soc.h>
#include <r_elc.h>
struct renesas_ra_elc_config {
const elc_cfg_t fsp_cfg;
const struct device *clock_dev;
const struct clock_control_ra_subsys_cfg clock_subsys;
};
struct renesas_ra_elc_data {
elc_instance_ctrl_t fsp_ctrl;
};
static int renesas_ra_elc_software_event_generate(const struct device *dev, uint32_t event)
{
struct renesas_ra_elc_data *data = (struct renesas_ra_elc_data *const)(dev)->data;
fsp_err_t err;
err = R_ELC_SoftwareEventGenerate(&data->fsp_ctrl, event);
if (err != FSP_SUCCESS) {
return -EIO;
}
return 0;
}
static int renesas_ra_elc_link_set(const struct device *dev, uint32_t peripheral, uint32_t event)
{
struct renesas_ra_elc_data *data = (struct renesas_ra_elc_data *const)(dev)->data;
fsp_err_t err;
if (BIT(peripheral) & BSP_ELC_PERIPHERAL_MASK) {
err = R_ELC_LinkSet(&data->fsp_ctrl, peripheral, event);
if (err != FSP_SUCCESS) {
return -EIO;
}
} else {
return -EINVAL;
}
return 0;
}
static int renesas_ra_elc_link_break(const struct device *dev, uint32_t peripheral)
{
struct renesas_ra_elc_data *data = (struct renesas_ra_elc_data *const)(dev)->data;
fsp_err_t err;
if (BIT(peripheral) & BSP_ELC_PERIPHERAL_MASK) {
err = R_ELC_LinkBreak(&data->fsp_ctrl, peripheral);
if (err != FSP_SUCCESS) {
return -EIO;
}
} else {
return -EINVAL;
}
return 0;
}
static int renesas_ra_elc_enable(const struct device *dev)
{
struct renesas_ra_elc_data *data = (struct renesas_ra_elc_data *const)(dev)->data;
fsp_err_t err;
err = R_ELC_Enable(&data->fsp_ctrl);
if (err != FSP_SUCCESS) {
return -EIO;
}
return 0;
}
static int renesas_ra_elc_disable(const struct device *dev)
{
struct renesas_ra_elc_data *data = (struct renesas_ra_elc_data *const)(dev)->data;
fsp_err_t err;
err = R_ELC_Disable(&data->fsp_ctrl);
if (err != FSP_SUCCESS) {
return -EIO;
}
return 0;
}
static int renesas_ra_elc_init(const struct device *dev)
{
struct renesas_ra_elc_data *data = (struct renesas_ra_elc_data *const)(dev)->data;
struct renesas_ra_elc_config *cfg = (struct renesas_ra_elc_config *const)(dev)->config;
fsp_err_t err;
int ret;
if (!device_is_ready(cfg->clock_dev)) {
return -ENODEV;
}
ret = clock_control_on(cfg->clock_dev, (clock_control_subsys_t)&cfg->clock_subsys);
if (ret < 0) {
return ret;
}
err = R_ELC_Open(&data->fsp_ctrl, &cfg->fsp_cfg);
if (err != FSP_SUCCESS) {
return -EIO;
}
return 0;
}
static DEVICE_API(renesas_elc, renesas_ra_elc_driver_api) = {
.software_event_generate = renesas_ra_elc_software_event_generate,
.link_set = renesas_ra_elc_link_set,
.link_break = renesas_ra_elc_link_break,
.enable = renesas_ra_elc_enable,
.disable = renesas_ra_elc_disable,
};
#define RA_ELC_INIT(inst) \
static const struct renesas_ra_elc_config renesas_ra_elc_config_##inst = { \
.fsp_cfg = \
{ \
.link = {0}, \
.p_extend = NULL, \
}, \
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(inst)), \
.clock_subsys = \
{ \
.mstp = (uint32_t)DT_INST_CLOCKS_CELL_BY_IDX(inst, 0, mstp), \
.stop_bit = DT_INST_CLOCKS_CELL_BY_IDX(inst, 0, stop_bit), \
}, \
}; \
static struct renesas_ra_elc_data renesas_ra_elc_data_##inst; \
DEVICE_DT_INST_DEFINE(inst, renesas_ra_elc_init, NULL, &renesas_ra_elc_data_##inst, \
&renesas_ra_elc_config_##inst, PRE_KERNEL_1, \
CONFIG_RENESAS_ELC_INIT_PRIORITY, &renesas_ra_elc_driver_api);
DT_INST_FOREACH_STATUS_OKAY(RA_ELC_INIT)

View file

@ -0,0 +1,23 @@
# Copyright (c) 2025 Renesas Electronics Corporation
# SPDX-License-Identifier: Apache-2.0
description: Renesas RA Event Link Controller
compatible: "renesas,ra-elc"
include: [base.yaml]
properties:
reg:
required: true
clocks:
required: true
"#renesas-elc-cells":
type: int
const: 2
renesas-elc-cells:
- peripheral
- event

View file

@ -186,6 +186,11 @@ config USE_RA_FSP_OSPI_B_NOR_FLASH
help
Enable RA FSP Octal-SPI driver
config USE_RA_FSP_ELC
bool
help
Enable RA FSP ELC driver
endif # HAS_RENESAS_RA_FSP
if HAS_RENESAS_RZ_FSP