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 #define EVENTS_IDX_MAX NRF_VPR_EVENTS_TRIGGERED_MAX
16
17 #define VEVIF_EVENTS_NUM DT_INST_PROP(0, nordic_events)
18 #define VEVIF_EVENTS_MASK DT_INST_PROP(0, nordic_events_mask)
19
20 BUILD_ASSERT(DT_INST_PROP(0, nordic_events) <= NRF_VPR_EVENTS_TRIGGERED_COUNT,
21 "Number of events exceeds maximum");
22
vevif_event_tx_is_valid(uint32_t id)23 static inline bool vevif_event_tx_is_valid(uint32_t id)
24 {
25 return (id < EVENTS_IDX_MAX) && ((VEVIF_EVENTS_MASK & BIT(id)) != 0U);
26 }
27
vevif_event_tx_send(const struct device * dev,uint32_t id,const struct mbox_msg * msg)28 static int vevif_event_tx_send(const struct device *dev, uint32_t id, const struct mbox_msg *msg)
29 {
30 ARG_UNUSED(dev);
31
32 if (!vevif_event_tx_is_valid(id)) {
33 return -EINVAL;
34 }
35
36 if (msg != NULL) {
37 return -EMSGSIZE;
38 }
39
40 nrf_vpr_csr_vevif_events_trigger(BIT(id));
41
42 #if defined(CONFIG_MBOX_NRF_VEVIF_EVENT_USE_54L_ERRATA_16)
43 while (!nrf_vpr_csr_vevif_events_get()) {
44 ;
45 }
46 nrf_vpr_csr_vevif_events_set(0);
47 #endif
48
49 return 0;
50 }
51
vevif_event_tx_mtu_get(const struct device * dev)52 static int vevif_event_tx_mtu_get(const struct device *dev)
53 {
54 ARG_UNUSED(dev);
55
56 return 0;
57 }
58
vevif_event_tx_max_channels_get(const struct device * dev)59 static uint32_t vevif_event_tx_max_channels_get(const struct device *dev)
60 {
61 ARG_UNUSED(dev);
62
63 return VEVIF_EVENTS_NUM;
64 }
65
66 static DEVICE_API(mbox, vevif_event_tx_driver_api) = {
67 .send = vevif_event_tx_send,
68 .mtu_get = vevif_event_tx_mtu_get,
69 .max_channels_get = vevif_event_tx_max_channels_get,
70 };
71
72 DEVICE_DT_INST_DEFINE(0, NULL, NULL, NULL, NULL, POST_KERNEL, CONFIG_MBOX_INIT_PRIORITY,
73 &vevif_event_tx_driver_api);
74