Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * OMAP mailbox driver |
| 3 | * |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 4 | * Copyright (C) 2006-2009 Nokia Corporation. All rights reserved. |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 5 | * |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 6 | * Contact: Hiroshi DOYU <Hiroshi.DOYU@nokia.com> |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | * 02110-1301 USA |
| 21 | * |
| 22 | */ |
| 23 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 24 | #include <linux/module.h> |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/device.h> |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 27 | #include <linux/delay.h> |
Hiroshi DOYU | 8dff0fa | 2009-03-23 18:07:32 -0700 | [diff] [blame] | 28 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 29 | #include <plat/mailbox.h> |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 30 | |
| 31 | static struct omap_mbox *mboxes; |
| 32 | static DEFINE_RWLOCK(mboxes_lock); |
| 33 | |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 34 | static int mbox_configured; |
| 35 | |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 36 | /* Mailbox FIFO handle functions */ |
| 37 | static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox) |
| 38 | { |
| 39 | return mbox->ops->fifo_read(mbox); |
| 40 | } |
| 41 | static inline void mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg) |
| 42 | { |
| 43 | mbox->ops->fifo_write(mbox, msg); |
| 44 | } |
| 45 | static inline int mbox_fifo_empty(struct omap_mbox *mbox) |
| 46 | { |
| 47 | return mbox->ops->fifo_empty(mbox); |
| 48 | } |
| 49 | static inline int mbox_fifo_full(struct omap_mbox *mbox) |
| 50 | { |
| 51 | return mbox->ops->fifo_full(mbox); |
| 52 | } |
| 53 | |
| 54 | /* Mailbox IRQ handle functions */ |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 55 | static inline void ack_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) |
| 56 | { |
| 57 | if (mbox->ops->ack_irq) |
| 58 | mbox->ops->ack_irq(mbox, irq); |
| 59 | } |
| 60 | static inline int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) |
| 61 | { |
| 62 | return mbox->ops->is_irq(mbox, irq); |
| 63 | } |
| 64 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 65 | /* |
| 66 | * message sender |
| 67 | */ |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 68 | static int __mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 69 | { |
| 70 | int ret = 0, i = 1000; |
| 71 | |
| 72 | while (mbox_fifo_full(mbox)) { |
| 73 | if (mbox->ops->type == OMAP_MBOX_TYPE2) |
| 74 | return -1; |
| 75 | if (--i == 0) |
| 76 | return -1; |
| 77 | udelay(1); |
| 78 | } |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 79 | mbox_fifo_write(mbox, msg); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 80 | return ret; |
| 81 | } |
| 82 | |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 83 | struct omap_msg_tx_data { |
| 84 | mbox_msg_t msg; |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | static void omap_msg_tx_end_io(struct request *rq, int error) |
| 88 | { |
| 89 | kfree(rq->special); |
| 90 | __blk_put_request(rq->q, rq); |
| 91 | } |
| 92 | |
C A Subramaniam | b2b6362 | 2009-11-22 10:11:20 -0800 | [diff] [blame] | 93 | int omap_mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 94 | { |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 95 | struct omap_msg_tx_data *tx_data; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 96 | struct request *rq; |
| 97 | struct request_queue *q = mbox->txq->queue; |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 98 | |
| 99 | tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC); |
| 100 | if (unlikely(!tx_data)) |
| 101 | return -ENOMEM; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 102 | |
| 103 | rq = blk_get_request(q, WRITE, GFP_ATOMIC); |
| 104 | if (unlikely(!rq)) { |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 105 | kfree(tx_data); |
| 106 | return -ENOMEM; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 109 | tx_data->msg = msg; |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 110 | rq->end_io = omap_msg_tx_end_io; |
| 111 | blk_insert_request(q, rq, 0, tx_data); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 112 | |
| 113 | schedule_work(&mbox->txq->work); |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 114 | return 0; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 115 | } |
| 116 | EXPORT_SYMBOL(omap_mbox_msg_send); |
| 117 | |
| 118 | static void mbox_tx_work(struct work_struct *work) |
| 119 | { |
| 120 | int ret; |
| 121 | struct request *rq; |
| 122 | struct omap_mbox_queue *mq = container_of(work, |
| 123 | struct omap_mbox_queue, work); |
| 124 | struct omap_mbox *mbox = mq->queue->queuedata; |
| 125 | struct request_queue *q = mbox->txq->queue; |
| 126 | |
| 127 | while (1) { |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 128 | struct omap_msg_tx_data *tx_data; |
| 129 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 130 | spin_lock(q->queue_lock); |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 131 | rq = blk_fetch_request(q); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 132 | spin_unlock(q->queue_lock); |
| 133 | |
| 134 | if (!rq) |
| 135 | break; |
| 136 | |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 137 | tx_data = rq->special; |
| 138 | |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 139 | ret = __mbox_msg_send(mbox, tx_data->msg); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 140 | if (ret) { |
Hiroshi DOYU | eb18858 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 141 | omap_mbox_enable_irq(mbox, IRQ_TX); |
Tejun Heo | 296b2f6 | 2009-05-08 11:54:15 +0900 | [diff] [blame] | 142 | spin_lock(q->queue_lock); |
| 143 | blk_requeue_request(q, rq); |
| 144 | spin_unlock(q->queue_lock); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 145 | return; |
| 146 | } |
| 147 | |
| 148 | spin_lock(q->queue_lock); |
Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 149 | __blk_end_request_all(rq, 0); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 150 | spin_unlock(q->queue_lock); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * Message receiver(workqueue) |
| 156 | */ |
| 157 | static void mbox_rx_work(struct work_struct *work) |
| 158 | { |
| 159 | struct omap_mbox_queue *mq = |
| 160 | container_of(work, struct omap_mbox_queue, work); |
| 161 | struct omap_mbox *mbox = mq->queue->queuedata; |
| 162 | struct request_queue *q = mbox->rxq->queue; |
| 163 | struct request *rq; |
| 164 | mbox_msg_t msg; |
| 165 | unsigned long flags; |
| 166 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 167 | while (1) { |
| 168 | spin_lock_irqsave(q->queue_lock, flags); |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 169 | rq = blk_fetch_request(q); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 170 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 171 | if (!rq) |
| 172 | break; |
| 173 | |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 174 | msg = (mbox_msg_t)rq->special; |
Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 175 | blk_end_request_all(rq, 0); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 176 | mbox->rxq->callback((void *)msg); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Mailbox interrupt handler |
| 182 | */ |
Hiroshi DOYU | bfe1f6a | 2009-11-22 10:11:18 -0800 | [diff] [blame] | 183 | static void mbox_txq_fn(struct request_queue *q) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 184 | { |
| 185 | } |
| 186 | |
Hiroshi DOYU | bfe1f6a | 2009-11-22 10:11:18 -0800 | [diff] [blame] | 187 | static void mbox_rxq_fn(struct request_queue *q) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 188 | { |
| 189 | } |
| 190 | |
| 191 | static void __mbox_tx_interrupt(struct omap_mbox *mbox) |
| 192 | { |
Hiroshi DOYU | eb18858 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 193 | omap_mbox_disable_irq(mbox, IRQ_TX); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 194 | ack_mbox_irq(mbox, IRQ_TX); |
| 195 | schedule_work(&mbox->txq->work); |
| 196 | } |
| 197 | |
| 198 | static void __mbox_rx_interrupt(struct omap_mbox *mbox) |
| 199 | { |
| 200 | struct request *rq; |
| 201 | mbox_msg_t msg; |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 202 | struct request_queue *q = mbox->rxq->queue; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 203 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 204 | while (!mbox_fifo_empty(mbox)) { |
| 205 | rq = blk_get_request(q, WRITE, GFP_ATOMIC); |
| 206 | if (unlikely(!rq)) |
| 207 | goto nomem; |
| 208 | |
| 209 | msg = mbox_fifo_read(mbox); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 210 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 211 | |
Tejun Heo | ec24751 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 212 | blk_insert_request(q, rq, 0, (void *)msg); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 213 | if (mbox->ops->type == OMAP_MBOX_TYPE1) |
| 214 | break; |
| 215 | } |
| 216 | |
| 217 | /* no more messages in the fifo. clear IRQ source. */ |
| 218 | ack_mbox_irq(mbox, IRQ_RX); |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 219 | nomem: |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 220 | schedule_work(&mbox->rxq->work); |
| 221 | } |
| 222 | |
| 223 | static irqreturn_t mbox_interrupt(int irq, void *p) |
| 224 | { |
Jeff Garzik | 2a7057e | 2007-10-26 05:40:22 -0400 | [diff] [blame] | 225 | struct omap_mbox *mbox = p; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 226 | |
| 227 | if (is_mbox_irq(mbox, IRQ_TX)) |
| 228 | __mbox_tx_interrupt(mbox); |
| 229 | |
| 230 | if (is_mbox_irq(mbox, IRQ_RX)) |
| 231 | __mbox_rx_interrupt(mbox); |
| 232 | |
| 233 | return IRQ_HANDLED; |
| 234 | } |
| 235 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 236 | static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox, |
Hiroshi DOYU | bfe1f6a | 2009-11-22 10:11:18 -0800 | [diff] [blame] | 237 | request_fn_proc *proc, |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 238 | void (*work) (struct work_struct *)) |
| 239 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 240 | struct request_queue *q; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 241 | struct omap_mbox_queue *mq; |
| 242 | |
| 243 | mq = kzalloc(sizeof(struct omap_mbox_queue), GFP_KERNEL); |
| 244 | if (!mq) |
| 245 | return NULL; |
| 246 | |
| 247 | spin_lock_init(&mq->lock); |
| 248 | |
| 249 | q = blk_init_queue(proc, &mq->lock); |
| 250 | if (!q) |
| 251 | goto error; |
| 252 | q->queuedata = mbox; |
| 253 | mq->queue = q; |
| 254 | |
| 255 | INIT_WORK(&mq->work, work); |
| 256 | |
| 257 | return mq; |
| 258 | error: |
| 259 | kfree(mq); |
| 260 | return NULL; |
| 261 | } |
| 262 | |
| 263 | static void mbox_queue_free(struct omap_mbox_queue *q) |
| 264 | { |
| 265 | blk_cleanup_queue(q->queue); |
| 266 | kfree(q); |
| 267 | } |
| 268 | |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 269 | static int omap_mbox_startup(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 270 | { |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 271 | int ret = 0; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 272 | struct omap_mbox_queue *mq; |
| 273 | |
| 274 | if (likely(mbox->ops->startup)) { |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 275 | write_lock(&mboxes_lock); |
| 276 | if (!mbox_configured) |
| 277 | ret = mbox->ops->startup(mbox); |
| 278 | |
| 279 | if (unlikely(ret)) { |
| 280 | write_unlock(&mboxes_lock); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 281 | return ret; |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 282 | } |
| 283 | mbox_configured++; |
| 284 | write_unlock(&mboxes_lock); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 285 | } |
| 286 | |
C A Subramaniam | 5e68382 | 2009-11-22 10:11:23 -0800 | [diff] [blame^] | 287 | ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED, |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 288 | mbox->name, mbox); |
| 289 | if (unlikely(ret)) { |
| 290 | printk(KERN_ERR |
| 291 | "failed to register mailbox interrupt:%d\n", ret); |
| 292 | goto fail_request_irq; |
| 293 | } |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 294 | |
| 295 | mq = mbox_queue_alloc(mbox, mbox_txq_fn, mbox_tx_work); |
| 296 | if (!mq) { |
| 297 | ret = -ENOMEM; |
| 298 | goto fail_alloc_txq; |
| 299 | } |
| 300 | mbox->txq = mq; |
| 301 | |
| 302 | mq = mbox_queue_alloc(mbox, mbox_rxq_fn, mbox_rx_work); |
| 303 | if (!mq) { |
| 304 | ret = -ENOMEM; |
| 305 | goto fail_alloc_rxq; |
| 306 | } |
| 307 | mbox->rxq = mq; |
| 308 | |
| 309 | return 0; |
| 310 | |
| 311 | fail_alloc_rxq: |
| 312 | mbox_queue_free(mbox->txq); |
| 313 | fail_alloc_txq: |
| 314 | free_irq(mbox->irq, mbox); |
| 315 | fail_request_irq: |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 316 | if (unlikely(mbox->ops->shutdown)) |
| 317 | mbox->ops->shutdown(mbox); |
| 318 | |
| 319 | return ret; |
| 320 | } |
| 321 | |
| 322 | static void omap_mbox_fini(struct omap_mbox *mbox) |
| 323 | { |
| 324 | mbox_queue_free(mbox->txq); |
| 325 | mbox_queue_free(mbox->rxq); |
| 326 | |
| 327 | free_irq(mbox->irq, mbox); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 328 | |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 329 | if (unlikely(mbox->ops->shutdown)) { |
| 330 | write_lock(&mboxes_lock); |
| 331 | if (mbox_configured > 0) |
| 332 | mbox_configured--; |
| 333 | if (!mbox_configured) |
| 334 | mbox->ops->shutdown(mbox); |
| 335 | write_unlock(&mboxes_lock); |
| 336 | } |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static struct omap_mbox **find_mboxes(const char *name) |
| 340 | { |
| 341 | struct omap_mbox **p; |
| 342 | |
| 343 | for (p = &mboxes; *p; p = &(*p)->next) { |
| 344 | if (strcmp((*p)->name, name) == 0) |
| 345 | break; |
| 346 | } |
| 347 | |
| 348 | return p; |
| 349 | } |
| 350 | |
| 351 | struct omap_mbox *omap_mbox_get(const char *name) |
| 352 | { |
| 353 | struct omap_mbox *mbox; |
| 354 | int ret; |
| 355 | |
| 356 | read_lock(&mboxes_lock); |
| 357 | mbox = *(find_mboxes(name)); |
| 358 | if (mbox == NULL) { |
| 359 | read_unlock(&mboxes_lock); |
| 360 | return ERR_PTR(-ENOENT); |
| 361 | } |
| 362 | |
| 363 | read_unlock(&mboxes_lock); |
| 364 | |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 365 | ret = omap_mbox_startup(mbox); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 366 | if (ret) |
| 367 | return ERR_PTR(-ENODEV); |
| 368 | |
| 369 | return mbox; |
| 370 | } |
| 371 | EXPORT_SYMBOL(omap_mbox_get); |
| 372 | |
| 373 | void omap_mbox_put(struct omap_mbox *mbox) |
| 374 | { |
| 375 | omap_mbox_fini(mbox); |
| 376 | } |
| 377 | EXPORT_SYMBOL(omap_mbox_put); |
| 378 | |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 379 | int omap_mbox_register(struct device *parent, struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 380 | { |
| 381 | int ret = 0; |
| 382 | struct omap_mbox **tmp; |
| 383 | |
| 384 | if (!mbox) |
| 385 | return -EINVAL; |
| 386 | if (mbox->next) |
| 387 | return -EBUSY; |
| 388 | |
| 389 | write_lock(&mboxes_lock); |
| 390 | tmp = find_mboxes(mbox->name); |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 391 | if (*tmp) { |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 392 | ret = -EBUSY; |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 393 | write_unlock(&mboxes_lock); |
| 394 | goto err_find; |
| 395 | } |
| 396 | *tmp = mbox; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 397 | write_unlock(&mboxes_lock); |
| 398 | |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 399 | return 0; |
| 400 | |
| 401 | err_find: |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 402 | return ret; |
| 403 | } |
| 404 | EXPORT_SYMBOL(omap_mbox_register); |
| 405 | |
| 406 | int omap_mbox_unregister(struct omap_mbox *mbox) |
| 407 | { |
| 408 | struct omap_mbox **tmp; |
| 409 | |
| 410 | write_lock(&mboxes_lock); |
| 411 | tmp = &mboxes; |
| 412 | while (*tmp) { |
| 413 | if (mbox == *tmp) { |
| 414 | *tmp = mbox->next; |
| 415 | mbox->next = NULL; |
| 416 | write_unlock(&mboxes_lock); |
| 417 | return 0; |
| 418 | } |
| 419 | tmp = &(*tmp)->next; |
| 420 | } |
| 421 | write_unlock(&mboxes_lock); |
| 422 | |
| 423 | return -EINVAL; |
| 424 | } |
| 425 | EXPORT_SYMBOL(omap_mbox_unregister); |
| 426 | |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 427 | static int __init omap_mbox_init(void) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 428 | { |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 429 | return 0; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 430 | } |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 431 | module_init(omap_mbox_init); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 432 | |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 433 | static void __exit omap_mbox_exit(void) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 434 | { |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 435 | } |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 436 | module_exit(omap_mbox_exit); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 437 | |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 438 | MODULE_LICENSE("GPL v2"); |
| 439 | MODULE_DESCRIPTION("omap mailbox: interrupt driven messaging"); |
| 440 | MODULE_AUTHOR("Toshihiro Kobayashi and Hiroshi DOYU"); |