1 /*
2 * Copyright (c) 2024 Nordic Semiconductor ASA
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6 #define DT_DRV_COMPAT nordic_nrf_vevif_task_tx
7
8 #include <zephyr/devicetree.h>
9 #include <zephyr/drivers/mbox.h>
10
11 #include <haly/nrfy_vpr.h>
12
13 #if defined(CONFIG_SOC_NRF54L15_ENGA_CPUAPP)
14 #define TASKS_IDX_MAX 17U
15 #else
16 #define TASKS_IDX_MAX NRF_VPR_TASKS_TRIGGER_MAX
17 #endif
18
19 struct mbox_vevif_task_tx_conf {
20 NRF_VPR_Type *vpr;
21 uint32_t tasks_mask;
22 uint8_t tasks;
23 };
24
vevif_task_tx_is_valid(const struct device * dev,uint32_t id)25 static inline bool vevif_task_tx_is_valid(const struct device *dev, uint32_t id)
26 {
27 const struct mbox_vevif_task_tx_conf *config = dev->config;
28
29 return ((id <= TASKS_IDX_MAX) && ((config->tasks_mask & BIT(id)) != 0U));
30 }
31
vevif_task_tx_send(const struct device * dev,uint32_t id,const struct mbox_msg * msg)32 static int vevif_task_tx_send(const struct device *dev, uint32_t id, const struct mbox_msg *msg)
33 {
34 const struct mbox_vevif_task_tx_conf *config = dev->config;
35
36 if (!vevif_task_tx_is_valid(dev, id)) {
37 return -EINVAL;
38 }
39
40 if (msg != NULL) {
41 return -ENOTSUP;
42 }
43
44 nrfy_vpr_task_trigger(config->vpr, nrfy_vpr_trigger_task_get(id));
45
46 return 0;
47 }
48
vevif_task_tx_mtu_get(const struct device * dev)49 static int vevif_task_tx_mtu_get(const struct device *dev)
50 {
51 ARG_UNUSED(dev);
52
53 return 0;
54 }
55
vevif_task_tx_max_channels_get(const struct device * dev)56 static uint32_t vevif_task_tx_max_channels_get(const struct device *dev)
57 {
58 const struct mbox_vevif_task_tx_conf *config = dev->config;
59
60 return config->tasks;
61 }
62
63 static const struct mbox_driver_api vevif_task_tx_driver_api = {
64 .send = vevif_task_tx_send,
65 .mtu_get = vevif_task_tx_mtu_get,
66 .max_channels_get = vevif_task_tx_max_channels_get,
67 };
68
69 #define VEVIF_TASK_TX_DEFINE(inst) \
70 BUILD_ASSERT(DT_INST_PROP(inst, nordic_tasks) <= VPR_TASKS_TRIGGER_MaxCount, \
71 "Number of tasks exceeds maximum"); \
72 \
73 static const struct mbox_vevif_task_tx_conf conf##inst = { \
74 .vpr = (NRF_VPR_Type *)DT_INST_REG_ADDR(inst), \
75 .tasks = DT_INST_PROP(inst, nordic_tasks), \
76 .tasks_mask = DT_INST_PROP(inst, nordic_tasks_mask), \
77 }; \
78 \
79 DEVICE_DT_INST_DEFINE(inst, NULL, NULL, NULL, &conf##inst, POST_KERNEL, \
80 CONFIG_MBOX_INIT_PRIORITY, &vevif_task_tx_driver_api);
81
82 DT_INST_FOREACH_STATUS_OKAY(VEVIF_TASK_TX_DEFINE)
83