@@ -35,7 +35,7 @@ static struct omap_mbox *mboxes;
static DEFINE_SPINLOCK(mboxes_lock);
static bool rq_full;
-static int mbox_configured;
+static atomic_t mbox_refcount = ATOMIC_INIT(0);
/* Mailbox FIFO handle functions */
static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
@@ -243,16 +243,13 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
struct omap_mbox_queue *mq;
if (likely(mbox->ops->startup)) {
- spin_lock(&mboxes_lock);
- if (!mbox_configured)
+ if (atomic_inc_return(&mbox_refcount) == 1)
ret = mbox->ops->startup(mbox);
if (unlikely(ret)) {
- spin_unlock(&mboxes_lock);
+ atomic_dec(&mbox_refcount);
return ret;
}
- mbox_configured++;
- spin_unlock(&mboxes_lock);
}
ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED,
@@ -284,8 +281,10 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
fail_alloc_txq:
free_irq(mbox->irq, mbox);
fail_request_irq:
- if (likely(mbox->ops->shutdown))
- mbox->ops->shutdown(mbox);
+ if (likely(mbox->ops->shutdown)) {
+ if (atomic_dec_return(&mbox_refcount) == 0)
+ mbox->ops->shutdown(mbox);
+ }
return ret;
}
@@ -298,12 +297,8 @@ static void omap_mbox_fini(struct omap_mbox *mbox)
free_irq(mbox->irq, mbox);
if (likely(mbox->ops->shutdown)) {
- spin_lock(&mboxes_lock);
- if (mbox_configured > 0)
- mbox_configured--;
- if (!mbox_configured)
+ if (atomic_dec_return(&mbox_refcount) == 0)
mbox->ops->shutdown(mbox);
- spin_unlock(&mboxes_lock);
}
}