Commit afcfb7e5105ef01ec46a6c896b20e210a07ee094
Committed by
Ye Li
1 parent
3733fc85c1
Exists in
smarc_8mm-imx_v2018.03_4.14.98_2.0.0_ga
and in
5 other branches
MLK-14938-23 mailbox: enable mbox_send non-blocking use
Add a timeout to allow non-blocking use in the same way as mbox_recv Signed-off-by: Teo Hall <teo.hall@nxp.com> (cherry picked from commit c2296701fa91dc8d4144c84c19ffe40dba3df88c)
Showing 2 changed files with 19 additions and 3 deletions Side-by-side Diff
drivers/mailbox/mailbox-uclass.c
... | ... | @@ -100,13 +100,29 @@ |
100 | 100 | return ops->free(chan); |
101 | 101 | } |
102 | 102 | |
103 | -int mbox_send(struct mbox_chan *chan, const void *data) | |
103 | +int mbox_send(struct mbox_chan *chan, const void *data, ulong timeout_us) | |
104 | 104 | { |
105 | 105 | struct mbox_ops *ops = mbox_dev_ops(chan->dev); |
106 | + ulong start_time; | |
107 | + int ret; | |
106 | 108 | |
107 | 109 | debug("%s(chan=%p, data=%p)\n", __func__, chan, data); |
108 | 110 | |
109 | - return ops->send(chan, data); | |
111 | + start_time = timer_get_us(); | |
112 | + /* | |
113 | + * Account for partial us ticks, but if timeout_us is 0, ensure we | |
114 | + * still don't wait at all. | |
115 | + */ | |
116 | + if (timeout_us) | |
117 | + timeout_us++; | |
118 | + | |
119 | + for (;;) { | |
120 | + ret = ops->send(chan, data); | |
121 | + if (ret != -EBUSY) | |
122 | + return ret; | |
123 | + if ((timer_get_us() - start_time) >= timeout_us) | |
124 | + return -ETIMEDOUT; | |
125 | + } | |
110 | 126 | } |
111 | 127 | |
112 | 128 | int mbox_recv(struct mbox_chan *chan, void *data, ulong timeout_us) |
include/mailbox.h
... | ... | @@ -124,7 +124,7 @@ |
124 | 124 | * will ignore this parameter. |
125 | 125 | * @return 0 if OK, or a negative error code. |
126 | 126 | */ |
127 | -int mbox_send(struct mbox_chan *chan, const void *data); | |
127 | +int mbox_send(struct mbox_chan *chan, const void *data, ulong timeout_us); | |
128 | 128 | |
129 | 129 | /** |
130 | 130 | * mbox_recv - Receive any available message from a mailbox channel |
-
mentioned in commit cc86ad
-
mentioned in commit cc86ad
-
mentioned in commit db2466
-
mentioned in commit db2466
-
mentioned in commit db2466
-
mentioned in commit db2466
-
mentioned in commit 77df52
-
mentioned in commit 77df52
-
mentioned in commit db2466
-
mentioned in commit 77df52
-
mentioned in commit 77df52
-
mentioned in commit 77df52
-
mentioned in commit 77df52
-
mentioned in commit 4e1f73