summaryrefslogtreecommitdiff
path: root/drivers/mailbox
diff options
context:
space:
mode:
authorTeo Hall <teo.hall@nxp.com>2016-09-12 14:12:25 -0500
committerYe Li <ye.li@nxp.com>2018-04-27 02:32:30 -0700
commitafcfb7e5105ef01ec46a6c896b20e210a07ee094 (patch)
tree22033d701a4725f7eacdaedff5b4e0d6b4c8fa7a /drivers/mailbox
parent3733fc85c1f29f2d0ac2af42eca64d5939902fe3 (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)
Diffstat (limited to 'drivers/mailbox')
-rw-r--r--drivers/mailbox/mailbox-uclass.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/drivers/mailbox/mailbox-uclass.c b/drivers/mailbox/mailbox-uclass.c
index 822ae5b45e..e149bf5dca 100644
--- a/drivers/mailbox/mailbox-uclass.c
+++ b/drivers/mailbox/mailbox-uclass.c
@@ -100,13 +100,29 @@ int mbox_free(struct mbox_chan *chan)
return ops->free(chan);
}
-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)