blob: 42377ef9ea3d3fb4c5231622b21e4bc6714294ce [file] [log] [blame]
Hiroshi DOYU340a6142006-12-07 15:43:59 -08001/*
2 * OMAP mailbox driver
3 *
Hiroshi DOYUf48cca82009-03-23 18:07:24 -07004 * Copyright (C) 2006-2009 Nokia Corporation. All rights reserved.
Hiroshi DOYU340a6142006-12-07 15:43:59 -08005 *
Hiroshi DOYUf48cca82009-03-23 18:07:24 -07006 * Contact: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
Hiroshi DOYU340a6142006-12-07 15:43:59 -08007 *
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 DOYU340a6142006-12-07 15:43:59 -080024#include <linux/interrupt.h>
Felipe Contrerasb3e69142010-06-11 15:51:49 +000025#include <linux/spinlock.h>
26#include <linux/mutex.h>
Hiroshi DOYU340a6142006-12-07 15:43:59 -080027#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000029#include <linux/kfifo.h>
30#include <linux/err.h>
Kanigeri, Hari58256302010-11-29 20:24:14 +000031#include <linux/notifier.h>
Paul Gortmaker73017a52011-07-31 16:14:14 -040032#include <linux/module.h>
Hiroshi DOYU8dff0fa2009-03-23 18:07:32 -070033
Tony Lindgrence491cf2009-10-20 09:40:47 -070034#include <plat/mailbox.h>
Hiroshi DOYU340a6142006-12-07 15:43:59 -080035
Felipe Contreras9c80c8c2010-06-11 15:51:46 +000036static struct omap_mbox **mboxes;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080037
C A Subramaniam5f00ec62009-11-22 10:11:22 -080038static int mbox_configured;
Hiroshi DOYU72b917e2010-02-18 00:48:55 -060039static DEFINE_MUTEX(mbox_configured_lock);
C A Subramaniam5f00ec62009-11-22 10:11:22 -080040
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000041static unsigned int mbox_kfifo_size = CONFIG_OMAP_MBOX_KFIFO_SIZE;
42module_param(mbox_kfifo_size, uint, S_IRUGO);
43MODULE_PARM_DESC(mbox_kfifo_size, "Size of omap's mailbox kfifo (bytes)");
44
Hiroshi DOYU9ae0ee02009-03-23 18:07:26 -070045/* Mailbox FIFO handle functions */
46static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
47{
48 return mbox->ops->fifo_read(mbox);
49}
50static inline void mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
51{
52 mbox->ops->fifo_write(mbox, msg);
53}
54static inline int mbox_fifo_empty(struct omap_mbox *mbox)
55{
56 return mbox->ops->fifo_empty(mbox);
57}
58static inline int mbox_fifo_full(struct omap_mbox *mbox)
59{
60 return mbox->ops->fifo_full(mbox);
61}
62
63/* Mailbox IRQ handle functions */
Hiroshi DOYU9ae0ee02009-03-23 18:07:26 -070064static inline void ack_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
65{
66 if (mbox->ops->ack_irq)
67 mbox->ops->ack_irq(mbox, irq);
68}
69static inline int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
70{
71 return mbox->ops->is_irq(mbox, irq);
72}
73
Hiroshi DOYU340a6142006-12-07 15:43:59 -080074/*
75 * message sender
76 */
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000077static int __mbox_poll_for_space(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080078{
79 int ret = 0, i = 1000;
80
81 while (mbox_fifo_full(mbox)) {
82 if (mbox->ops->type == OMAP_MBOX_TYPE2)
83 return -1;
84 if (--i == 0)
85 return -1;
86 udelay(1);
87 }
Hiroshi DOYU340a6142006-12-07 15:43:59 -080088 return ret;
89}
90
C A Subramaniamb2b63622009-11-22 10:11:20 -080091int omap_mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080092{
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000093 struct omap_mbox_queue *mq = mbox->txq;
94 int ret = 0, len;
C A Subramaniam5ed8d322009-11-22 10:11:24 -080095
Kanigeri, Haria42743c2010-11-29 20:24:13 +000096 spin_lock_bh(&mq->lock);
Tejun Heoec247512009-04-23 11:05:20 +090097
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000098 if (kfifo_avail(&mq->fifo) < sizeof(msg)) {
99 ret = -ENOMEM;
100 goto out;
101 }
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800102
Kanigeri, Haria42743c2010-11-29 20:24:13 +0000103 if (kfifo_is_empty(&mq->fifo) && !__mbox_poll_for_space(mbox)) {
104 mbox_fifo_write(mbox, msg);
105 goto out;
106 }
107
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000108 len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
109 WARN_ON(len != sizeof(msg));
110
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800111 tasklet_schedule(&mbox->txq->tasklet);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800112
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000113out:
Kanigeri, Haria42743c2010-11-29 20:24:13 +0000114 spin_unlock_bh(&mq->lock);
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000115 return ret;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800116}
117EXPORT_SYMBOL(omap_mbox_msg_send);
118
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800119static void mbox_tx_tasklet(unsigned long tx_data)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800120{
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800121 struct omap_mbox *mbox = (struct omap_mbox *)tx_data;
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000122 struct omap_mbox_queue *mq = mbox->txq;
123 mbox_msg_t msg;
124 int ret;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800125
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000126 while (kfifo_len(&mq->fifo)) {
127 if (__mbox_poll_for_space(mbox)) {
Hiroshi DOYUeb188582009-11-22 10:11:22 -0800128 omap_mbox_enable_irq(mbox, IRQ_TX);
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000129 break;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800130 }
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000131
132 ret = kfifo_out(&mq->fifo, (unsigned char *)&msg,
133 sizeof(msg));
134 WARN_ON(ret != sizeof(msg));
135
136 mbox_fifo_write(mbox, msg);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800137 }
138}
139
140/*
141 * Message receiver(workqueue)
142 */
143static void mbox_rx_work(struct work_struct *work)
144{
145 struct omap_mbox_queue *mq =
146 container_of(work, struct omap_mbox_queue, work);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800147 mbox_msg_t msg;
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000148 int len;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800149
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000150 while (kfifo_len(&mq->fifo) >= sizeof(msg)) {
151 len = kfifo_out(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
152 WARN_ON(len != sizeof(msg));
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800153
Kanigeri, Hari58256302010-11-29 20:24:14 +0000154 blocking_notifier_call_chain(&mq->mbox->notifier, len,
155 (void *)msg);
Fernando Guzman Lugod2295042010-11-29 20:24:11 +0000156 spin_lock_irq(&mq->lock);
157 if (mq->full) {
158 mq->full = false;
159 omap_mbox_enable_irq(mq->mbox, IRQ_RX);
160 }
161 spin_unlock_irq(&mq->lock);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800162 }
163}
164
165/*
166 * Mailbox interrupt handler
167 */
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800168static void __mbox_tx_interrupt(struct omap_mbox *mbox)
169{
Hiroshi DOYUeb188582009-11-22 10:11:22 -0800170 omap_mbox_disable_irq(mbox, IRQ_TX);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800171 ack_mbox_irq(mbox, IRQ_TX);
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800172 tasklet_schedule(&mbox->txq->tasklet);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800173}
174
175static void __mbox_rx_interrupt(struct omap_mbox *mbox)
176{
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000177 struct omap_mbox_queue *mq = mbox->rxq;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800178 mbox_msg_t msg;
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000179 int len;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800180
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800181 while (!mbox_fifo_empty(mbox)) {
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000182 if (unlikely(kfifo_avail(&mq->fifo) < sizeof(msg))) {
Fernando Guzman Lugo1ea5d6d2010-02-08 13:35:40 -0600183 omap_mbox_disable_irq(mbox, IRQ_RX);
Fernando Guzman Lugod2295042010-11-29 20:24:11 +0000184 mq->full = true;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800185 goto nomem;
Fernando Guzman Lugo1ea5d6d2010-02-08 13:35:40 -0600186 }
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800187
188 msg = mbox_fifo_read(mbox);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800189
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000190 len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
191 WARN_ON(len != sizeof(msg));
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800192
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800193 if (mbox->ops->type == OMAP_MBOX_TYPE1)
194 break;
195 }
196
197 /* no more messages in the fifo. clear IRQ source. */
198 ack_mbox_irq(mbox, IRQ_RX);
Hiroshi DOYUf48cca82009-03-23 18:07:24 -0700199nomem:
Tejun Heoc4873002011-01-26 12:12:50 +0100200 schedule_work(&mbox->rxq->work);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800201}
202
203static irqreturn_t mbox_interrupt(int irq, void *p)
204{
Jeff Garzik2a7057e2007-10-26 05:40:22 -0400205 struct omap_mbox *mbox = p;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800206
207 if (is_mbox_irq(mbox, IRQ_TX))
208 __mbox_tx_interrupt(mbox);
209
210 if (is_mbox_irq(mbox, IRQ_RX))
211 __mbox_rx_interrupt(mbox);
212
213 return IRQ_HANDLED;
214}
215
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800216static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox,
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800217 void (*work) (struct work_struct *),
218 void (*tasklet)(unsigned long))
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800219{
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800220 struct omap_mbox_queue *mq;
221
222 mq = kzalloc(sizeof(struct omap_mbox_queue), GFP_KERNEL);
223 if (!mq)
224 return NULL;
225
226 spin_lock_init(&mq->lock);
227
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000228 if (kfifo_alloc(&mq->fifo, mbox_kfifo_size, GFP_KERNEL))
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800229 goto error;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800230
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800231 if (work)
232 INIT_WORK(&mq->work, work);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800233
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800234 if (tasklet)
235 tasklet_init(&mq->tasklet, tasklet, (unsigned long)mbox);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800236 return mq;
237error:
238 kfree(mq);
239 return NULL;
240}
241
242static void mbox_queue_free(struct omap_mbox_queue *q)
243{
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000244 kfifo_free(&q->fifo);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800245 kfree(q);
246}
247
Hiroshi DOYUc7c158e2009-11-22 10:11:19 -0800248static int omap_mbox_startup(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800249{
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800250 int ret = 0;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800251 struct omap_mbox_queue *mq;
252
Kanigeri, Hari58256302010-11-29 20:24:14 +0000253 mutex_lock(&mbox_configured_lock);
254 if (!mbox_configured++) {
255 if (likely(mbox->ops->startup)) {
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800256 ret = mbox->ops->startup(mbox);
Kanigeri, Hari58256302010-11-29 20:24:14 +0000257 if (unlikely(ret))
258 goto fail_startup;
259 } else
260 goto fail_startup;
261 }
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800262
Kanigeri, Hari58256302010-11-29 20:24:14 +0000263 if (!mbox->use_count++) {
264 ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED,
265 mbox->name, mbox);
266 if (unlikely(ret)) {
267 pr_err("failed to register mailbox interrupt:%d\n",
268 ret);
269 goto fail_request_irq;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800270 }
Kanigeri, Hari58256302010-11-29 20:24:14 +0000271 mq = mbox_queue_alloc(mbox, NULL, mbox_tx_tasklet);
272 if (!mq) {
273 ret = -ENOMEM;
274 goto fail_alloc_txq;
275 }
276 mbox->txq = mq;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800277
Kanigeri, Hari58256302010-11-29 20:24:14 +0000278 mq = mbox_queue_alloc(mbox, mbox_rx_work, NULL);
279 if (!mq) {
280 ret = -ENOMEM;
281 goto fail_alloc_rxq;
282 }
283 mbox->rxq = mq;
284 mq->mbox = mbox;
Juan Gutierrez1d8a0e92012-05-13 15:33:04 +0300285
286 omap_mbox_enable_irq(mbox, IRQ_RX);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800287 }
Kanigeri, Hari58256302010-11-29 20:24:14 +0000288 mutex_unlock(&mbox_configured_lock);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800289 return 0;
290
Kanigeri, Hariab66ac32010-11-29 20:24:12 +0000291fail_alloc_rxq:
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800292 mbox_queue_free(mbox->txq);
Kanigeri, Hariab66ac32010-11-29 20:24:12 +0000293fail_alloc_txq:
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800294 free_irq(mbox->irq, mbox);
Kanigeri, Hariab66ac32010-11-29 20:24:12 +0000295fail_request_irq:
Ohad Ben-Cohen01072d82010-05-05 15:33:08 +0000296 if (mbox->ops->shutdown)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800297 mbox->ops->shutdown(mbox);
Kanigeri, Hari58256302010-11-29 20:24:14 +0000298 mbox->use_count--;
299fail_startup:
300 mbox_configured--;
301 mutex_unlock(&mbox_configured_lock);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800302 return ret;
303}
304
305static void omap_mbox_fini(struct omap_mbox *mbox)
306{
Kanigeri, Hari58256302010-11-29 20:24:14 +0000307 mutex_lock(&mbox_configured_lock);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800308
Kanigeri, Hari58256302010-11-29 20:24:14 +0000309 if (!--mbox->use_count) {
Juan Gutierrez1d8a0e92012-05-13 15:33:04 +0300310 omap_mbox_disable_irq(mbox, IRQ_RX);
Kanigeri, Hari58256302010-11-29 20:24:14 +0000311 free_irq(mbox->irq, mbox);
312 tasklet_kill(&mbox->txq->tasklet);
Tejun Heo43829732012-08-20 14:51:24 -0700313 flush_work(&mbox->rxq->work);
Kanigeri, Hari58256302010-11-29 20:24:14 +0000314 mbox_queue_free(mbox->txq);
315 mbox_queue_free(mbox->rxq);
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800316 }
Kanigeri, Hari58256302010-11-29 20:24:14 +0000317
318 if (likely(mbox->ops->shutdown)) {
319 if (!--mbox_configured)
320 mbox->ops->shutdown(mbox);
321 }
322
323 mutex_unlock(&mbox_configured_lock);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800324}
325
Kanigeri, Hari58256302010-11-29 20:24:14 +0000326struct omap_mbox *omap_mbox_get(const char *name, struct notifier_block *nb)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800327{
Kevin Hilmanc0377322011-02-11 19:56:43 +0000328 struct omap_mbox *_mbox, *mbox = NULL;
329 int i, ret;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800330
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000331 if (!mboxes)
332 return ERR_PTR(-EINVAL);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800333
Kevin Hilmanc0377322011-02-11 19:56:43 +0000334 for (i = 0; (_mbox = mboxes[i]); i++) {
335 if (!strcmp(_mbox->name, name)) {
336 mbox = _mbox;
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000337 break;
Kevin Hilmanc0377322011-02-11 19:56:43 +0000338 }
339 }
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000340
341 if (!mbox)
342 return ERR_PTR(-ENOENT);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800343
Kanigeri, Hari58256302010-11-29 20:24:14 +0000344 if (nb)
345 blocking_notifier_chain_register(&mbox->notifier, nb);
346
Juan Gutierrez1d8a0e92012-05-13 15:33:04 +0300347 ret = omap_mbox_startup(mbox);
348 if (ret) {
349 blocking_notifier_chain_unregister(&mbox->notifier, nb);
350 return ERR_PTR(-ENODEV);
351 }
352
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800353 return mbox;
354}
355EXPORT_SYMBOL(omap_mbox_get);
356
Kanigeri, Hari58256302010-11-29 20:24:14 +0000357void omap_mbox_put(struct omap_mbox *mbox, struct notifier_block *nb)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800358{
Kanigeri, Hari58256302010-11-29 20:24:14 +0000359 blocking_notifier_chain_unregister(&mbox->notifier, nb);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800360 omap_mbox_fini(mbox);
361}
362EXPORT_SYMBOL(omap_mbox_put);
363
Hiroshi DOYU6b233982010-05-18 16:15:32 +0300364static struct class omap_mbox_class = { .name = "mbox", };
365
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000366int omap_mbox_register(struct device *parent, struct omap_mbox **list)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800367{
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000368 int ret;
369 int i;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800370
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000371 mboxes = list;
372 if (!mboxes)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800373 return -EINVAL;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800374
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000375 for (i = 0; mboxes[i]; i++) {
376 struct omap_mbox *mbox = mboxes[i];
377 mbox->dev = device_create(&omap_mbox_class,
378 parent, 0, mbox, "%s", mbox->name);
379 if (IS_ERR(mbox->dev)) {
380 ret = PTR_ERR(mbox->dev);
381 goto err_out;
382 }
Kanigeri, Hari58256302010-11-29 20:24:14 +0000383
384 BLOCKING_INIT_NOTIFIER_HEAD(&mbox->notifier);
Hiroshi DOYUf48cca82009-03-23 18:07:24 -0700385 }
Hiroshi DOYUf48cca82009-03-23 18:07:24 -0700386 return 0;
387
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000388err_out:
389 while (i--)
390 device_unregister(mboxes[i]->dev);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800391 return ret;
392}
393EXPORT_SYMBOL(omap_mbox_register);
394
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000395int omap_mbox_unregister(void)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800396{
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000397 int i;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800398
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000399 if (!mboxes)
400 return -EINVAL;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800401
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000402 for (i = 0; mboxes[i]; i++)
403 device_unregister(mboxes[i]->dev);
404 mboxes = NULL;
405 return 0;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800406}
407EXPORT_SYMBOL(omap_mbox_unregister);
408
Hiroshi DOYUc7c158e2009-11-22 10:11:19 -0800409static int __init omap_mbox_init(void)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800410{
Hiroshi DOYU6b233982010-05-18 16:15:32 +0300411 int err;
412
413 err = class_register(&omap_mbox_class);
414 if (err)
415 return err;
416
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000417 /* kfifo size sanity check: alignment and minimal size */
418 mbox_kfifo_size = ALIGN(mbox_kfifo_size, sizeof(mbox_msg_t));
Kanigeri, Hariab66ac32010-11-29 20:24:12 +0000419 mbox_kfifo_size = max_t(unsigned int, mbox_kfifo_size,
420 sizeof(mbox_msg_t));
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000421
Hiroshi DOYUc7c158e2009-11-22 10:11:19 -0800422 return 0;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800423}
Hiroshi DOYU6b233982010-05-18 16:15:32 +0300424subsys_initcall(omap_mbox_init);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800425
Hiroshi DOYUc7c158e2009-11-22 10:11:19 -0800426static void __exit omap_mbox_exit(void)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800427{
Hiroshi DOYU6b233982010-05-18 16:15:32 +0300428 class_unregister(&omap_mbox_class);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800429}
Hiroshi DOYUc7c158e2009-11-22 10:11:19 -0800430module_exit(omap_mbox_exit);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800431
Hiroshi DOYUf48cca82009-03-23 18:07:24 -0700432MODULE_LICENSE("GPL v2");
433MODULE_DESCRIPTION("omap mailbox: interrupt driven messaging");
Ohad Ben-Cohenf3753252010-05-05 15:33:07 +0000434MODULE_AUTHOR("Toshihiro Kobayashi");
435MODULE_AUTHOR("Hiroshi DOYU");