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_event_tx
7
8 #include <zephyr/devicetree.h>
9 #include <zephyr/drivers/mbox.h>
10
11 #include <hal/nrf_vpr.h>
12 #include <hal/nrf_vpr_csr.h>
13 #include <hal/nrf_vpr_csr_vevif.h>
14
15 #if defined(CONFIG_SOC_NRF54L15_ENGA_CPUFLPR)
16 #define EVENTS_IDX_MAX 17U
17 #else
18 #define EVENTS_IDX_MAX NRF_VPR_EVENTS_TRIGGERED_MAX
19 #endif
20
21 #define VEVIF_EVENTS_NUM DT_INST_PROP(0, nordic_events)
22 #define VEVIF_EVENTS_MASK DT_INST_PROP(0, nordic_events_mask)
23
24 BUILD_ASSERT(DT_INST_PROP(0, nordic_events) <= NRF_VPR_EVENTS_TRIGGERED_COUNT,
25 "Number of events exceeds maximum");
26
vevif_event_tx_is_valid(uint32_t id)27 static inline bool vevif_event_tx_is_valid(uint32_t id)
28 {
29 return (id < EVENTS_IDX_MAX) && ((VEVIF_EVENTS_MASK & BIT(id)) != 0U);
30 }
31
vevif_event_tx_send(const struct device * dev,uint32_t id,const struct mbox_msg * msg)32 static int vevif_event_tx_send(const struct device *dev, uint32_t id, const struct mbox_msg *msg)
33 {
34 ARG_UNUSED(dev);
35
36 if (!vevif_event_tx_is_valid(id)) {
37 return -EINVAL;
38 }
39
40 if (msg != NULL) {
41 return -ENOTSUP;
42 }
43
44 nrf_vpr_csr_vevif_events_trigger(BIT(id));
45
46 return 0;
47 }
48
vevif_event_tx_mtu_get(const struct device * dev)49 static int vevif_event_tx_mtu_get(const struct device *dev)
50 {
51 ARG_UNUSED(dev);
52
53 return 0;
54 }
55
vevif_event_tx_max_channels_get(const struct device * dev)56 static uint32_t vevif_event_tx_max_channels_get(const struct device *dev)
57 {
58 ARG_UNUSED(dev);
59
60 return VEVIF_EVENTS_NUM;
61 }
62
63 static const struct mbox_driver_api vevif_event_tx_driver_api = {
64 .send = vevif_event_tx_send,
65 .mtu_get = vevif_event_tx_mtu_get,
66 .max_channels_get = vevif_event_tx_max_channels_get,
67 };
68
69 DEVICE_DT_INST_DEFINE(0, NULL, NULL, NULL, NULL, POST_KERNEL, CONFIG_MBOX_INIT_PRIORITY,
70 &vevif_event_tx_driver_api);
71