1 /*
2 * Copyright (c) 2024 Nordic Semiconductor ASA
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6 #define DT_DRV_COMPAT nordic_nrf_bellboard_tx
7
8 #include <zephyr/devicetree.h>
9 #include <zephyr/drivers/mbox.h>
10
11 #include <haly/nrfy_bellboard.h>
12
13 struct mbox_bellboard_tx_conf {
14 NRF_BELLBOARD_Type *bellboard;
15 };
16
bellboard_tx_send(const struct device * dev,uint32_t id,const struct mbox_msg * msg)17 static int bellboard_tx_send(const struct device *dev, uint32_t id, const struct mbox_msg *msg)
18 {
19 const struct mbox_bellboard_tx_conf *config = dev->config;
20
21 if (id >= BELLBOARD_TASKS_TRIGGER_MaxCount) {
22 return -EINVAL;
23 }
24
25 if (msg != NULL) {
26 return -EMSGSIZE;
27 }
28
29 nrfy_bellboard_task_trigger(config->bellboard, nrf_bellboard_trigger_task_get(id));
30
31 return 0;
32 }
33
bellboard_tx_mtu_get(const struct device * dev)34 static int bellboard_tx_mtu_get(const struct device *dev)
35 {
36 ARG_UNUSED(dev);
37
38 return 0;
39 }
40
bellboard_tx_max_channels_get(const struct device * dev)41 static uint32_t bellboard_tx_max_channels_get(const struct device *dev)
42 {
43 ARG_UNUSED(dev);
44
45 return BELLBOARD_TASKS_TRIGGER_MaxCount;
46 }
47
48 static DEVICE_API(mbox, bellboard_tx_driver_api) = {
49 .send = bellboard_tx_send,
50 .mtu_get = bellboard_tx_mtu_get,
51 .max_channels_get = bellboard_tx_max_channels_get,
52 };
53
54 #define BELLBOARD_REMOTE_DEFINE(inst) \
55 static const struct mbox_bellboard_tx_conf conf##inst = { \
56 .bellboard = (NRF_BELLBOARD_Type *)DT_INST_REG_ADDR(inst), \
57 }; \
58 \
59 DEVICE_DT_INST_DEFINE(inst, NULL, NULL, NULL, &conf##inst, POST_KERNEL, \
60 CONFIG_MBOX_INIT_PRIORITY, &bellboard_tx_driver_api);
61
62 DT_INST_FOREACH_STATUS_OKAY(BELLBOARD_REMOTE_DEFINE)
63