28 #include <linux/slab.h>
32 #include <linux/module.h>
38 static int mbox_configured;
41 static unsigned int mbox_kfifo_size = CONFIG_OMAP_MBOX_KFIFO_SIZE;
48 return mbox->
ops->fifo_read(mbox);
52 mbox->
ops->fifo_write(mbox, msg);
54 static inline int mbox_fifo_empty(
struct omap_mbox *mbox)
56 return mbox->
ops->fifo_empty(mbox);
58 static inline int mbox_fifo_full(
struct omap_mbox *mbox)
60 return mbox->
ops->fifo_full(mbox);
66 if (mbox->
ops->ack_irq)
67 mbox->
ops->ack_irq(mbox, irq);
71 return mbox->
ops->is_irq(mbox, irq);
77 static int __mbox_poll_for_space(
struct omap_mbox *mbox)
79 int ret = 0,
i = 1000;
81 while (mbox_fifo_full(mbox)) {
96 spin_lock_bh(&mq->
lock);
104 mbox_fifo_write(mbox, msg);
111 tasklet_schedule(&mbox->
txq->tasklet);
114 spin_unlock_bh(&mq->
lock);
119 static void mbox_tx_tasklet(
unsigned long tx_data)
127 if (__mbox_poll_for_space(mbox)) {
128 omap_mbox_enable_irq(mbox,
IRQ_TX);
136 mbox_fifo_write(mbox, msg);
151 len =
kfifo_out(&mq->
fifo, (
unsigned char *)&msg,
sizeof(msg));
156 spin_lock_irq(&mq->
lock);
161 spin_unlock_irq(&mq->
lock);
168 static void __mbox_tx_interrupt(
struct omap_mbox *mbox)
170 omap_mbox_disable_irq(mbox,
IRQ_TX);
171 ack_mbox_irq(mbox,
IRQ_TX);
172 tasklet_schedule(&mbox->
txq->tasklet);
175 static void __mbox_rx_interrupt(
struct omap_mbox *mbox)
181 while (!mbox_fifo_empty(mbox)) {
183 omap_mbox_disable_irq(mbox,
IRQ_RX);
188 msg = mbox_fifo_read(mbox);
190 len =
kfifo_in(&mq->
fifo, (
unsigned char *)&msg,
sizeof(msg));
198 ack_mbox_irq(mbox,
IRQ_RX);
207 if (is_mbox_irq(mbox,
IRQ_TX))
208 __mbox_tx_interrupt(mbox);
210 if (is_mbox_irq(mbox,
IRQ_RX))
211 __mbox_rx_interrupt(mbox);
218 void (*
tasklet)(
unsigned long))
248 static int omap_mbox_startup(
struct omap_mbox *mbox)
254 if (!mbox_configured++) {
256 ret = mbox->
ops->startup(mbox);
267 pr_err(
"failed to register mailbox interrupt:%d\n",
269 goto fail_request_irq;
271 mq = mbox_queue_alloc(mbox,
NULL, mbox_tx_tasklet);
278 mq = mbox_queue_alloc(mbox, mbox_rx_work,
NULL);
286 omap_mbox_enable_irq(mbox,
IRQ_RX);
292 mbox_queue_free(mbox->
txq);
296 if (mbox->
ops->shutdown)
297 mbox->
ops->shutdown(mbox);
305 static void omap_mbox_fini(
struct omap_mbox *mbox)
310 omap_mbox_disable_irq(mbox,
IRQ_RX);
314 mbox_queue_free(mbox->
txq);
315 mbox_queue_free(mbox->
rxq);
319 if (!--mbox_configured)
320 mbox->
ops->shutdown(mbox);
334 for (i = 0; (_mbox = mboxes[
i]); i++) {
347 ret = omap_mbox_startup(mbox);
360 omap_mbox_fini(mbox);
364 static struct class omap_mbox_class = { .name =
"mbox", };
375 for (i = 0; mboxes[
i]; i++) {
378 parent, 0, mbox,
"%s", mbox->
name);
379 if (IS_ERR(mbox->
dev)) {
380 ret = PTR_ERR(mbox->
dev);
402 for (i = 0; mboxes[
i]; i++)
409 static int __init omap_mbox_init(
void)
419 mbox_kfifo_size =
max_t(
unsigned int, mbox_kfifo_size,
426 static void __exit omap_mbox_exit(
void)