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