blob: 69ddc9f76c13ebcdcad6b97b109e374f0b2960c4 [file] [log] [blame]
Hiroshi DOYU340a614a2006-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 DOYU340a614a2006-12-07 15:43:59 -08005 *
Hiroshi DOYUf48cca82009-03-23 18:07:24 -07006 * Contact: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
Hiroshi DOYU340a614a2006-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 DOYU340a614a2006-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 DOYU340a614a2006-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>
Hiroshi DOYU8dff0fa2009-03-23 18:07:32 -070032
Tony Lindgrence491cf2009-10-20 09:40:47 -070033#include <plat/mailbox.h>
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080034
Felipe Contreras9c80c8c2010-06-11 15:51:46 +000035static struct omap_mbox **mboxes;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080036
C A Subramaniam5f00ec62009-11-22 10:11:22 -080037static int mbox_configured;
Hiroshi DOYU72b917e2010-02-18 00:48:55 -060038static DEFINE_MUTEX(mbox_configured_lock);
C A Subramaniam5f00ec62009-11-22 10:11:22 -080039
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000040static unsigned int mbox_kfifo_size = CONFIG_OMAP_MBOX_KFIFO_SIZE;
41module_param(mbox_kfifo_size, uint, S_IRUGO);
42MODULE_PARM_DESC(mbox_kfifo_size, "Size of omap's mailbox kfifo (bytes)");
43
Hiroshi DOYU9ae0ee02009-03-23 18:07:26 -070044/* Mailbox FIFO handle functions */
45static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
46{
47 return mbox->ops->fifo_read(mbox);
48}
49static inline void mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
50{
51 mbox->ops->fifo_write(mbox, msg);
52}
53static inline int mbox_fifo_empty(struct omap_mbox *mbox)
54{
55 return mbox->ops->fifo_empty(mbox);
56}
57static inline int mbox_fifo_full(struct omap_mbox *mbox)
58{
59 return mbox->ops->fifo_full(mbox);
60}
61
62/* Mailbox IRQ handle functions */
Hiroshi DOYU9ae0ee02009-03-23 18:07:26 -070063static inline void ack_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
64{
65 if (mbox->ops->ack_irq)
66 mbox->ops->ack_irq(mbox, irq);
67}
68static inline int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
69{
70 return mbox->ops->is_irq(mbox, irq);
71}
72
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080073/*
74 * message sender
75 */
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000076static int __mbox_poll_for_space(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080077{
78 int ret = 0, i = 1000;
79
80 while (mbox_fifo_full(mbox)) {
81 if (mbox->ops->type == OMAP_MBOX_TYPE2)
82 return -1;
83 if (--i == 0)
84 return -1;
85 udelay(1);
86 }
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080087 return ret;
88}
89
C A Subramaniamb2b63622009-11-22 10:11:20 -080090int omap_mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080091{
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000092 struct omap_mbox_queue *mq = mbox->txq;
93 int ret = 0, len;
C A Subramaniam5ed8d322009-11-22 10:11:24 -080094
Kanigeri, Haria42743c2010-11-29 20:24:13 +000095 spin_lock_bh(&mq->lock);
Tejun Heoec247512009-04-23 11:05:20 +090096
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000097 if (kfifo_avail(&mq->fifo) < sizeof(msg)) {
98 ret = -ENOMEM;
99 goto out;
100 }
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800101
Kanigeri, Haria42743c2010-11-29 20:24:13 +0000102 if (kfifo_is_empty(&mq->fifo) && !__mbox_poll_for_space(mbox)) {
103 mbox_fifo_write(mbox, msg);
104 goto out;
105 }
106
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000107 len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
108 WARN_ON(len != sizeof(msg));
109
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800110 tasklet_schedule(&mbox->txq->tasklet);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800111
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000112out:
Kanigeri, Haria42743c2010-11-29 20:24:13 +0000113 spin_unlock_bh(&mq->lock);
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000114 return ret;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800115}
116EXPORT_SYMBOL(omap_mbox_msg_send);
117
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800118static void mbox_tx_tasklet(unsigned long tx_data)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800119{
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800120 struct omap_mbox *mbox = (struct omap_mbox *)tx_data;
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000121 struct omap_mbox_queue *mq = mbox->txq;
122 mbox_msg_t msg;
123 int ret;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800124
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000125 while (kfifo_len(&mq->fifo)) {
126 if (__mbox_poll_for_space(mbox)) {
Hiroshi DOYUeb188582009-11-22 10:11:22 -0800127 omap_mbox_enable_irq(mbox, IRQ_TX);
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000128 break;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800129 }
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000130
131 ret = kfifo_out(&mq->fifo, (unsigned char *)&msg,
132 sizeof(msg));
133 WARN_ON(ret != sizeof(msg));
134
135 mbox_fifo_write(mbox, msg);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800136 }
137}
138
139/*
140 * Message receiver(workqueue)
141 */
142static void mbox_rx_work(struct work_struct *work)
143{
144 struct omap_mbox_queue *mq =
145 container_of(work, struct omap_mbox_queue, work);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800146 mbox_msg_t msg;
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000147 int len;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800148
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000149 while (kfifo_len(&mq->fifo) >= sizeof(msg)) {
150 len = kfifo_out(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
151 WARN_ON(len != sizeof(msg));
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800152
Kanigeri, Hari58256302010-11-29 20:24:14 +0000153 blocking_notifier_call_chain(&mq->mbox->notifier, len,
154 (void *)msg);
Fernando Guzman Lugod2295042010-11-29 20:24:11 +0000155 spin_lock_irq(&mq->lock);
156 if (mq->full) {
157 mq->full = false;
158 omap_mbox_enable_irq(mq->mbox, IRQ_RX);
159 }
160 spin_unlock_irq(&mq->lock);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800161 }
162}
163
164/*
165 * Mailbox interrupt handler
166 */
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800167static void __mbox_tx_interrupt(struct omap_mbox *mbox)
168{
Hiroshi DOYUeb188582009-11-22 10:11:22 -0800169 omap_mbox_disable_irq(mbox, IRQ_TX);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800170 ack_mbox_irq(mbox, IRQ_TX);
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800171 tasklet_schedule(&mbox->txq->tasklet);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800172}
173
174static void __mbox_rx_interrupt(struct omap_mbox *mbox)
175{
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000176 struct omap_mbox_queue *mq = mbox->rxq;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800177 mbox_msg_t msg;
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000178 int len;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800179
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800180 while (!mbox_fifo_empty(mbox)) {
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000181 if (unlikely(kfifo_avail(&mq->fifo) < sizeof(msg))) {
Fernando Guzman Lugo1ea5d6d2010-02-08 13:35:40 -0600182 omap_mbox_disable_irq(mbox, IRQ_RX);
Fernando Guzman Lugod2295042010-11-29 20:24:11 +0000183 mq->full = true;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800184 goto nomem;
Fernando Guzman Lugo1ea5d6d2010-02-08 13:35:40 -0600185 }
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800186
187 msg = mbox_fifo_read(mbox);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800188
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000189 len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
190 WARN_ON(len != sizeof(msg));
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800191
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800192 if (mbox->ops->type == OMAP_MBOX_TYPE1)
193 break;
194 }
195
196 /* no more messages in the fifo. clear IRQ source. */
197 ack_mbox_irq(mbox, IRQ_RX);
Hiroshi DOYUf48cca82009-03-23 18:07:24 -0700198nomem:
Tejun Heoc4873002011-01-26 12:12:50 +0100199 schedule_work(&mbox->rxq->work);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800200}
201
202static irqreturn_t mbox_interrupt(int irq, void *p)
203{
Jeff Garzik2a7057e2007-10-26 05:40:22 -0400204 struct omap_mbox *mbox = p;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800205
206 if (is_mbox_irq(mbox, IRQ_TX))
207 __mbox_tx_interrupt(mbox);
208
209 if (is_mbox_irq(mbox, IRQ_RX))
210 __mbox_rx_interrupt(mbox);
211
212 return IRQ_HANDLED;
213}
214
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800215static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox,
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800216 void (*work) (struct work_struct *),
217 void (*tasklet)(unsigned long))
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800218{
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800219 struct omap_mbox_queue *mq;
220
221 mq = kzalloc(sizeof(struct omap_mbox_queue), GFP_KERNEL);
222 if (!mq)
223 return NULL;
224
225 spin_lock_init(&mq->lock);
226
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000227 if (kfifo_alloc(&mq->fifo, mbox_kfifo_size, GFP_KERNEL))
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800228 goto error;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800229
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800230 if (work)
231 INIT_WORK(&mq->work, work);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800232
C A Subramaniam5ed8d322009-11-22 10:11:24 -0800233 if (tasklet)
234 tasklet_init(&mq->tasklet, tasklet, (unsigned long)mbox);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800235 return mq;
236error:
237 kfree(mq);
238 return NULL;
239}
240
241static void mbox_queue_free(struct omap_mbox_queue *q)
242{
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000243 kfifo_free(&q->fifo);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800244 kfree(q);
245}
246
Hiroshi DOYUc7c158e2009-11-22 10:11:19 -0800247static int omap_mbox_startup(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800248{
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800249 int ret = 0;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800250 struct omap_mbox_queue *mq;
251
Kanigeri, Hari58256302010-11-29 20:24:14 +0000252 mutex_lock(&mbox_configured_lock);
253 if (!mbox_configured++) {
254 if (likely(mbox->ops->startup)) {
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800255 ret = mbox->ops->startup(mbox);
Kanigeri, Hari58256302010-11-29 20:24:14 +0000256 if (unlikely(ret))
257 goto fail_startup;
258 } else
259 goto fail_startup;
260 }
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800261
Kanigeri, Hari58256302010-11-29 20:24:14 +0000262 if (!mbox->use_count++) {
263 ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED,
264 mbox->name, mbox);
265 if (unlikely(ret)) {
266 pr_err("failed to register mailbox interrupt:%d\n",
267 ret);
268 goto fail_request_irq;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800269 }
Kanigeri, Hari58256302010-11-29 20:24:14 +0000270 mq = mbox_queue_alloc(mbox, NULL, mbox_tx_tasklet);
271 if (!mq) {
272 ret = -ENOMEM;
273 goto fail_alloc_txq;
274 }
275 mbox->txq = mq;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800276
Kanigeri, Hari58256302010-11-29 20:24:14 +0000277 mq = mbox_queue_alloc(mbox, mbox_rx_work, NULL);
278 if (!mq) {
279 ret = -ENOMEM;
280 goto fail_alloc_rxq;
281 }
282 mbox->rxq = mq;
283 mq->mbox = mbox;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800284 }
Kanigeri, Hari58256302010-11-29 20:24:14 +0000285 mutex_unlock(&mbox_configured_lock);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800286 return 0;
287
Kanigeri, Hariab66ac32010-11-29 20:24:12 +0000288fail_alloc_rxq:
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800289 mbox_queue_free(mbox->txq);
Kanigeri, Hariab66ac32010-11-29 20:24:12 +0000290fail_alloc_txq:
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800291 free_irq(mbox->irq, mbox);
Kanigeri, Hariab66ac32010-11-29 20:24:12 +0000292fail_request_irq:
Ohad Ben-Cohen01072d82010-05-05 15:33:08 +0000293 if (mbox->ops->shutdown)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800294 mbox->ops->shutdown(mbox);
Kanigeri, Hari58256302010-11-29 20:24:14 +0000295 mbox->use_count--;
296fail_startup:
297 mbox_configured--;
298 mutex_unlock(&mbox_configured_lock);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800299 return ret;
300}
301
302static void omap_mbox_fini(struct omap_mbox *mbox)
303{
Kanigeri, Hari58256302010-11-29 20:24:14 +0000304 mutex_lock(&mbox_configured_lock);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800305
Kanigeri, Hari58256302010-11-29 20:24:14 +0000306 if (!--mbox->use_count) {
307 free_irq(mbox->irq, mbox);
308 tasklet_kill(&mbox->txq->tasklet);
Tejun Heoc4873002011-01-26 12:12:50 +0100309 flush_work_sync(&mbox->rxq->work);
Kanigeri, Hari58256302010-11-29 20:24:14 +0000310 mbox_queue_free(mbox->txq);
311 mbox_queue_free(mbox->rxq);
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800312 }
Kanigeri, Hari58256302010-11-29 20:24:14 +0000313
314 if (likely(mbox->ops->shutdown)) {
315 if (!--mbox_configured)
316 mbox->ops->shutdown(mbox);
317 }
318
319 mutex_unlock(&mbox_configured_lock);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800320}
321
Kanigeri, Hari58256302010-11-29 20:24:14 +0000322struct omap_mbox *omap_mbox_get(const char *name, struct notifier_block *nb)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800323{
Kevin Hilmanc0377322011-02-11 19:56:43 +0000324 struct omap_mbox *_mbox, *mbox = NULL;
325 int i, ret;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800326
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000327 if (!mboxes)
328 return ERR_PTR(-EINVAL);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800329
Kevin Hilmanc0377322011-02-11 19:56:43 +0000330 for (i = 0; (_mbox = mboxes[i]); i++) {
331 if (!strcmp(_mbox->name, name)) {
332 mbox = _mbox;
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000333 break;
Kevin Hilmanc0377322011-02-11 19:56:43 +0000334 }
335 }
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000336
337 if (!mbox)
338 return ERR_PTR(-ENOENT);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800339
Hiroshi DOYUc7c158e2009-11-22 10:11:19 -0800340 ret = omap_mbox_startup(mbox);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800341 if (ret)
342 return ERR_PTR(-ENODEV);
343
Kanigeri, Hari58256302010-11-29 20:24:14 +0000344 if (nb)
345 blocking_notifier_chain_register(&mbox->notifier, nb);
346
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800347 return mbox;
348}
349EXPORT_SYMBOL(omap_mbox_get);
350
Kanigeri, Hari58256302010-11-29 20:24:14 +0000351void omap_mbox_put(struct omap_mbox *mbox, struct notifier_block *nb)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800352{
Kanigeri, Hari58256302010-11-29 20:24:14 +0000353 blocking_notifier_chain_unregister(&mbox->notifier, nb);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800354 omap_mbox_fini(mbox);
355}
356EXPORT_SYMBOL(omap_mbox_put);
357
Hiroshi DOYU6b233982010-05-18 16:15:32 +0300358static struct class omap_mbox_class = { .name = "mbox", };
359
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000360int omap_mbox_register(struct device *parent, struct omap_mbox **list)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800361{
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000362 int ret;
363 int i;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800364
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000365 mboxes = list;
366 if (!mboxes)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800367 return -EINVAL;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800368
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000369 for (i = 0; mboxes[i]; i++) {
370 struct omap_mbox *mbox = mboxes[i];
371 mbox->dev = device_create(&omap_mbox_class,
372 parent, 0, mbox, "%s", mbox->name);
373 if (IS_ERR(mbox->dev)) {
374 ret = PTR_ERR(mbox->dev);
375 goto err_out;
376 }
Kanigeri, Hari58256302010-11-29 20:24:14 +0000377
378 BLOCKING_INIT_NOTIFIER_HEAD(&mbox->notifier);
Hiroshi DOYUf48cca82009-03-23 18:07:24 -0700379 }
Hiroshi DOYUf48cca82009-03-23 18:07:24 -0700380 return 0;
381
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000382err_out:
383 while (i--)
384 device_unregister(mboxes[i]->dev);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800385 return ret;
386}
387EXPORT_SYMBOL(omap_mbox_register);
388
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000389int omap_mbox_unregister(void)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800390{
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000391 int i;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800392
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000393 if (!mboxes)
394 return -EINVAL;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800395
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000396 for (i = 0; mboxes[i]; i++)
397 device_unregister(mboxes[i]->dev);
398 mboxes = NULL;
399 return 0;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800400}
401EXPORT_SYMBOL(omap_mbox_unregister);
402
Hiroshi DOYUc7c158e2009-11-22 10:11:19 -0800403static int __init omap_mbox_init(void)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800404{
Hiroshi DOYU6b233982010-05-18 16:15:32 +0300405 int err;
406
407 err = class_register(&omap_mbox_class);
408 if (err)
409 return err;
410
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000411 /* kfifo size sanity check: alignment and minimal size */
412 mbox_kfifo_size = ALIGN(mbox_kfifo_size, sizeof(mbox_msg_t));
Kanigeri, Hariab66ac32010-11-29 20:24:12 +0000413 mbox_kfifo_size = max_t(unsigned int, mbox_kfifo_size,
414 sizeof(mbox_msg_t));
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +0000415
Hiroshi DOYUc7c158e2009-11-22 10:11:19 -0800416 return 0;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800417}
Hiroshi DOYU6b233982010-05-18 16:15:32 +0300418subsys_initcall(omap_mbox_init);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800419
Hiroshi DOYUc7c158e2009-11-22 10:11:19 -0800420static void __exit omap_mbox_exit(void)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800421{
Hiroshi DOYU6b233982010-05-18 16:15:32 +0300422 class_unregister(&omap_mbox_class);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800423}
Hiroshi DOYUc7c158e2009-11-22 10:11:19 -0800424module_exit(omap_mbox_exit);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800425
Hiroshi DOYUf48cca82009-03-23 18:07:24 -0700426MODULE_LICENSE("GPL v2");
427MODULE_DESCRIPTION("omap mailbox: interrupt driven messaging");
Ohad Ben-Cohenf3753252010-05-05 15:33:07 +0000428MODULE_AUTHOR("Toshihiro Kobayashi");
429MODULE_AUTHOR("Hiroshi DOYU");