MLK-14938-23 mailbox: enable mbox_send non-blocking use
authorTeo Hall <teo.hall@nxp.com>
Mon, 12 Sep 2016 19:12:25 +0000 (14:12 -0500)
committerJason Liu <jason.hui.liu@nxp.com>
Thu, 2 Nov 2017 18:36:51 +0000 (02:36 +0800)
Add a timeout to allow non-blocking use in the
same way as mbox_recv

Signed-off-by: Teo Hall <teo.hall@nxp.com>
drivers/mailbox/mailbox-uclass.c
include/mailbox.h

index 38448de..bb75105 100644 (file)
@@ -104,13 +104,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)
index a92a1a5..8d89f3f 100644 (file)
@@ -124,7 +124,7 @@ int mbox_free(struct mbox_chan *chan);
  *             will ignore this parameter.
  * @return 0 if OK, or a negative error code.
  */
-int mbox_send(struct mbox_chan *chan, const void *data);
+int mbox_send(struct mbox_chan *chan, const void *data, ulong timeout_us);
 
 /**
  * mbox_recv - Receive any available message from a mailbox channel