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