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