]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/mailbox/hi3660-mailbox.c
Merge tag 'selinux-pr-20190115' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / drivers / mailbox / hi3660-mailbox.c
index 3eea6b6424841ad16a726382045a5e19fe8be0d0..53f4bc2488c50c3a91988f06195d3415dff9c54c 100644 (file)
@@ -38,6 +38,7 @@
 #define MBOX_AUTOMATIC_ACK             1
 
 #define MBOX_STATE_IDLE                        BIT(4)
+#define MBOX_STATE_READY               BIT(5)
 #define MBOX_STATE_ACK                 BIT(7)
 
 #define MBOX_MSG_LEN                   8
@@ -91,8 +92,8 @@ static int hi3660_mbox_check_state(struct mbox_chan *chan)
        unsigned long val;
        unsigned int ret;
 
-       /* Mailbox is idle so directly bail out */
-       if (readl(base + MBOX_MODE_REG) & MBOX_STATE_IDLE)
+       /* Mailbox is ready to use */
+       if (readl(base + MBOX_MODE_REG) & MBOX_STATE_READY)
                return 0;
 
        /* Wait for acknowledge from remote */
@@ -103,9 +104,9 @@ static int hi3660_mbox_check_state(struct mbox_chan *chan)
                return ret;
        }
 
-       /* Ensure channel is released */
-       writel(0xffffffff, base + MBOX_IMASK_REG);
-       writel(BIT(mchan->ack_irq), base + MBOX_SRC_REG);
+       /* clear ack state, mailbox will get back to ready state */
+       writel(BIT(mchan->ack_irq), base + MBOX_ICLR_REG);
+
        return 0;
 }
 
@@ -160,10 +161,6 @@ static int hi3660_mbox_startup(struct mbox_chan *chan)
 {
        int ret;
 
-       ret = hi3660_mbox_check_state(chan);
-       if (ret)
-               return ret;
-
        ret = hi3660_mbox_unlock(chan);
        if (ret)
                return ret;
@@ -183,10 +180,11 @@ static int hi3660_mbox_send_data(struct mbox_chan *chan, void *msg)
        void __iomem *base = MBOX_BASE(mbox, ch);
        u32 *buf = msg;
        unsigned int i;
+       int ret;
 
-       /* Ensure channel is released */
-       writel_relaxed(0xffffffff, base + MBOX_IMASK_REG);
-       writel_relaxed(BIT(mchan->ack_irq), base + MBOX_SRC_REG);
+       ret = hi3660_mbox_check_state(chan);
+       if (ret)
+               return ret;
 
        /* Clear mask for destination interrupt */
        writel_relaxed(~BIT(mchan->dst_irq), base + MBOX_IMASK_REG);
@@ -206,7 +204,7 @@ static int hi3660_mbox_send_data(struct mbox_chan *chan, void *msg)
        return 0;
 }
 
-static struct mbox_chan_ops hi3660_mbox_ops = {
+static const struct mbox_chan_ops hi3660_mbox_ops = {
        .startup        = hi3660_mbox_startup,
        .send_data      = hi3660_mbox_send_data,
 };
@@ -267,7 +265,7 @@ static int hi3660_mbox_probe(struct platform_device *pdev)
        for (ch = 0; ch < MBOX_CHAN_MAX; ch++)
                chan[ch].con_priv = (void *)ch;
 
-       err = mbox_controller_register(&mbox->controller);
+       err = devm_mbox_controller_register(dev, &mbox->controller);
        if (err) {
                dev_err(dev, "Failed to register mailbox %d\n", err);
                return err;
@@ -278,17 +276,8 @@ static int hi3660_mbox_probe(struct platform_device *pdev)
        return 0;
 }
 
-static int hi3660_mbox_remove(struct platform_device *pdev)
-{
-       struct hi3660_mbox *mbox = platform_get_drvdata(pdev);
-
-       mbox_controller_unregister(&mbox->controller);
-       return 0;
-}
-
 static struct platform_driver hi3660_mbox_driver = {
        .probe  = hi3660_mbox_probe,
-       .remove = hi3660_mbox_remove,
        .driver = {
                .name = "hi3660-mbox",
                .of_match_table = hi3660_mbox_of_match,