|
10 | 10 | LOG_MODULE_REGISTER(scmi_mbox); |
11 | 11 |
|
12 | 12 | static void scmi_mbox_tx_reply_cb(const struct device *mbox, |
13 | | - mbox_channel_id_t channel_id, |
14 | | - void *user_data, |
15 | | - struct mbox_msg *data) |
| 13 | + mbox_channel_id_t channel_id, |
| 14 | + void *user_data, |
| 15 | + struct mbox_msg *data) |
| 16 | +{ |
| 17 | + struct scmi_channel *scmi_chan = user_data; |
| 18 | + |
| 19 | + if (scmi_chan->cb) { |
| 20 | + scmi_chan->cb(scmi_chan); |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +static void scmi_mbox_rx_notify_cb(const struct device *mbox, |
| 25 | + mbox_channel_id_t channel_id, |
| 26 | + void *user_data, |
| 27 | + struct mbox_msg *data) |
16 | 28 | { |
17 | 29 | struct scmi_channel *scmi_chan = user_data; |
18 | 30 |
|
@@ -71,25 +83,34 @@ static int scmi_mbox_setup_chan(const struct device *transport, |
71 | 83 | { |
72 | 84 | int ret; |
73 | 85 | struct scmi_mbox_channel *mbox_chan; |
74 | | - struct mbox_dt_spec *tx_reply; |
| 86 | + struct mbox_dt_spec *mbox_spec; |
75 | 87 |
|
76 | 88 | mbox_chan = chan->data; |
77 | 89 |
|
78 | | - if (mbox_chan->tx_reply.dev) { |
79 | | - tx_reply = &mbox_chan->tx_reply; |
| 90 | + if (tx) { |
| 91 | + mbox_spec = mbox_chan->tx_reply.dev ? &mbox_chan->tx_reply : &mbox_chan->tx; |
| 92 | + ret = mbox_register_callback_dt(mbox_spec, scmi_mbox_tx_reply_cb, chan); |
| 93 | + if (ret < 0) { |
| 94 | + LOG_ERR("failed to register reply cb on %s", |
| 95 | + mbox_chan->tx_reply.dev ? "tx_reply" : "tx"); |
| 96 | + return ret; |
| 97 | + } |
80 | 98 | } else { |
81 | | - tx_reply = &mbox_chan->tx; |
82 | | - } |
83 | | - |
84 | | - ret = mbox_register_callback_dt(tx_reply, scmi_mbox_tx_reply_cb, chan); |
85 | | - if (ret < 0) { |
86 | | - LOG_ERR("failed to register tx reply cb"); |
87 | | - return ret; |
| 99 | + if (!mbox_chan->rx.dev) { |
| 100 | + LOG_ERR("RX channel not defined"); |
| 101 | + return -ENOTSUP; |
| 102 | + } |
| 103 | + mbox_spec = &mbox_chan->rx; |
| 104 | + ret = mbox_register_callback_dt(&mbox_chan->rx, scmi_mbox_rx_notify_cb, chan); |
| 105 | + if (ret < 0) { |
| 106 | + LOG_ERR("failed to register notify cb on rx"); |
| 107 | + return ret; |
| 108 | + } |
88 | 109 | } |
89 | 110 |
|
90 | | - ret = mbox_set_enabled_dt(tx_reply, true); |
| 111 | + ret = mbox_set_enabled_dt(mbox_spec, true); |
91 | 112 | if (ret < 0) { |
92 | | - LOG_ERR("failed to enable tx reply dbell"); |
| 113 | + LOG_ERR("failed to enable %s dbell", tx ? "tx" : "rx"); |
93 | 114 | } |
94 | 115 |
|
95 | 116 | /* enable interrupt-based communication */ |
|
0 commit comments