diff options
author | Teo Hall <teo.hall@nxp.com> | 2016-09-12 14:12:25 -0500 |
---|---|---|
committer | Ye Li <ye.li@nxp.com> | 2022-04-06 14:30:56 +0800 |
commit | 4e1f73c20db49885779c813cc2b5c5292111e749 (patch) | |
tree | 72fa18b65d3fd42c5b6c030f4b09a832c38391b6 /drivers/mailbox | |
parent | cf2c8d3939cc6e459f070dcc251f741e2d5de04a (diff) |
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)
(cherry picked from commit afcfb7e5105ef01ec46a6c896b20e210a07ee094)
(cherry picked from commit cc86ad157e1c8405a78c392926bf4f96afaae9c1)
(cherry picked from commit 77df5264d279b8390e6ec5765e5080692789c022)
(cherry picked from commit 72d0cb6adf7d23ccd5693bc89b05e19402852de9)
Diffstat (limited to 'drivers/mailbox')
-rw-r--r-- | drivers/mailbox/mailbox-uclass.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/drivers/mailbox/mailbox-uclass.c b/drivers/mailbox/mailbox-uclass.c index 85ba8c5fd9..1a9c6918d8 100644 --- a/drivers/mailbox/mailbox-uclass.c +++ b/drivers/mailbox/mailbox-uclass.c @@ -115,13 +115,29 @@ int mbox_free(struct mbox_chan *chan) return 0; } -int mbox_send(struct mbox_chan *chan, const void *data) +int mbox_send(struct mbox_chan *chan, const void *data, ulong timeout_us) { struct mbox_ops *ops = mbox_dev_ops(chan->dev); + ulong start_time; + int ret; debug("%s(chan=%p, data=%p)\n", __func__, chan, data); - return ops->send(chan, data); + start_time = timer_get_us(); + /* + * Account for partial us ticks, but if timeout_us is 0, ensure we + * still don't wait at all. + */ + if (timeout_us) + timeout_us++; + + for (;;) { + ret = ops->send(chan, data); + if (ret != -EBUSY) + return ret; + if ((timer_get_us() - start_time) >= timeout_us) + return -ETIMEDOUT; + } } int mbox_recv(struct mbox_chan *chan, void *data, ulong timeout_us) |