blob: 281ab63424481b99535b2c7ebc5d08a24b6b12ae [file] [log] [blame]
Hiroshi DOYU340a6142006-12-07 15:43:59 -08001/*
Hiroshi DOYU733ecc52009-03-23 18:07:23 -07002 * Mailbox reservation modules for OMAP2/3
Hiroshi DOYU340a6142006-12-07 15:43:59 -08003 *
Hiroshi DOYU733ecc52009-03-23 18:07:23 -07004 * Copyright (C) 2006-2009 Nokia Corporation
Hiroshi DOYU340a6142006-12-07 15:43:59 -08005 * Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
Hiroshi DOYU733ecc52009-03-23 18:07:23 -07006 * and Paul Mundt
Hiroshi DOYU340a6142006-12-07 15:43:59 -08007 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12
13#include <linux/kernel.h>
14#include <linux/clk.h>
15#include <linux/err.h>
16#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010017#include <linux/io.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070018#include <plat/mailbox.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010019#include <mach/irqs.h>
Hiroshi DOYU340a6142006-12-07 15:43:59 -080020
C A Subramaniam5f00ec62009-11-22 10:11:22 -080021#define DRV_NAME "omap2-mailbox"
22
Hiroshi DOYU733ecc52009-03-23 18:07:23 -070023#define MAILBOX_REVISION 0x000
24#define MAILBOX_SYSCONFIG 0x010
25#define MAILBOX_SYSSTATUS 0x014
26#define MAILBOX_MESSAGE(m) (0x040 + 4 * (m))
27#define MAILBOX_FIFOSTATUS(m) (0x080 + 4 * (m))
28#define MAILBOX_MSGSTATUS(m) (0x0c0 + 4 * (m))
29#define MAILBOX_IRQSTATUS(u) (0x100 + 8 * (u))
30#define MAILBOX_IRQENABLE(u) (0x104 + 8 * (u))
31
C A Subramaniam5f00ec62009-11-22 10:11:22 -080032#define OMAP4_MAILBOX_IRQSTATUS(u) (0x104 + 10 * (u))
33#define OMAP4_MAILBOX_IRQENABLE(u) (0x108 + 10 * (u))
34#define OMAP4_MAILBOX_IRQENABLE_CLR(u) (0x10c + 10 * (u))
35
36#define MAILBOX_IRQ_NEWMSG(m) (1 << (2 * (m)))
37#define MAILBOX_IRQ_NOTFULL(m) (1 << (2 * (m) + 1))
Hiroshi DOYU340a6142006-12-07 15:43:59 -080038
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070039/* SYSCONFIG: register bit definition */
40#define AUTOIDLE (1 << 0)
41#define SOFTRESET (1 << 1)
42#define SMARTIDLE (2 << 3)
43
44/* SYSSTATUS: register bit definition */
45#define RESETDONE (1 << 0)
46
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070047#define MBOX_REG_SIZE 0x120
C A Subramaniam5f00ec62009-11-22 10:11:22 -080048
49#define OMAP4_MBOX_REG_SIZE 0x130
50
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070051#define MBOX_NR_REGS (MBOX_REG_SIZE / sizeof(u32))
C A Subramaniam5f00ec62009-11-22 10:11:22 -080052#define OMAP4_MBOX_NR_REGS (OMAP4_MBOX_REG_SIZE / sizeof(u32))
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070053
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070054static void __iomem *mbox_base;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080055
Hiroshi DOYU340a6142006-12-07 15:43:59 -080056struct omap_mbox2_fifo {
57 unsigned long msg;
58 unsigned long fifo_stat;
59 unsigned long msg_stat;
60};
61
62struct omap_mbox2_priv {
63 struct omap_mbox2_fifo tx_fifo;
64 struct omap_mbox2_fifo rx_fifo;
65 unsigned long irqenable;
66 unsigned long irqstatus;
67 u32 newmsg_bit;
68 u32 notfull_bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -080069 u32 ctx[OMAP4_MBOX_NR_REGS];
70 unsigned long irqdisable;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080071};
72
73static struct clk *mbox_ick_handle;
74
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +030075static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
76 omap_mbox_type_t irq);
77
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070078static inline unsigned int mbox_read_reg(size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080079{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070080 return __raw_readl(mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080081}
82
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070083static inline void mbox_write_reg(u32 val, size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080084{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070085 __raw_writel(val, mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080086}
87
88/* Mailbox H/W preparations */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +030089static int omap2_mbox_startup(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080090{
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070091 u32 l;
92 unsigned long timeout;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080093
94 mbox_ick_handle = clk_get(NULL, "mailboxes_ick");
95 if (IS_ERR(mbox_ick_handle)) {
C A Subramaniam5f00ec62009-11-22 10:11:22 -080096 printk(KERN_ERR "Could not get mailboxes_ick: %d\n",
97 PTR_ERR(mbox_ick_handle));
98 return PTR_ERR(mbox_ick_handle);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080099 }
100 clk_enable(mbox_ick_handle);
101
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -0700102 mbox_write_reg(SOFTRESET, MAILBOX_SYSCONFIG);
103 timeout = jiffies + msecs_to_jiffies(20);
104 do {
105 l = mbox_read_reg(MAILBOX_SYSSTATUS);
106 if (l & RESETDONE)
107 break;
Hiroshi DOYU055c49d2009-09-28 09:21:26 -0700108 } while (!time_after(jiffies, timeout));
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -0700109
110 if (!(l & RESETDONE)) {
111 pr_err("Can't take mmu out of reset\n");
112 return -ENODEV;
113 }
114
Hiroshi DOYU94fc58c2009-03-23 18:07:24 -0700115 l = mbox_read_reg(MAILBOX_REVISION);
116 pr_info("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));
117
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -0700118 l = SMARTIDLE | AUTOIDLE;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800119 mbox_write_reg(l, MAILBOX_SYSCONFIG);
120
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300121 omap2_mbox_enable_irq(mbox, IRQ_RX);
122
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800123 return 0;
124}
125
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300126static void omap2_mbox_shutdown(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800127{
128 clk_disable(mbox_ick_handle);
129 clk_put(mbox_ick_handle);
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800130 mbox_ick_handle = NULL;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800131}
132
133/* Mailbox FIFO handle functions */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300134static mbox_msg_t omap2_mbox_fifo_read(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800135{
136 struct omap_mbox2_fifo *fifo =
137 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
138 return (mbox_msg_t) mbox_read_reg(fifo->msg);
139}
140
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300141static void omap2_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800142{
143 struct omap_mbox2_fifo *fifo =
144 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
145 mbox_write_reg(msg, fifo->msg);
146}
147
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300148static int omap2_mbox_fifo_empty(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800149{
150 struct omap_mbox2_fifo *fifo =
151 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
152 return (mbox_read_reg(fifo->msg_stat) == 0);
153}
154
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300155static int omap2_mbox_fifo_full(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800156{
157 struct omap_mbox2_fifo *fifo =
158 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800159 return mbox_read_reg(fifo->fifo_stat);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800160}
161
162/* Mailbox IRQ handle functions */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300163static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800164 omap_mbox_type_t irq)
165{
166 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
167 u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
168
169 l = mbox_read_reg(p->irqenable);
170 l |= bit;
171 mbox_write_reg(l, p->irqenable);
172}
173
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300174static void omap2_mbox_disable_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800175 omap_mbox_type_t irq)
176{
177 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
178 u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800179 l = mbox_read_reg(p->irqdisable);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800180 l &= ~bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800181 mbox_write_reg(l, p->irqdisable);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800182}
183
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300184static void omap2_mbox_ack_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800185 omap_mbox_type_t irq)
186{
187 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
188 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
189
190 mbox_write_reg(bit, p->irqstatus);
Hiroshi DOYU88288802009-09-24 16:23:10 -0700191
192 /* Flush posted write for irq status to avoid spurious interrupts */
193 mbox_read_reg(p->irqstatus);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800194}
195
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300196static int omap2_mbox_is_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800197 omap_mbox_type_t irq)
198{
199 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
200 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
201 u32 enable = mbox_read_reg(p->irqenable);
202 u32 status = mbox_read_reg(p->irqstatus);
203
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800204 return (int)(enable & status & bit);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800205}
206
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700207static void omap2_mbox_save_ctx(struct omap_mbox *mbox)
208{
209 int i;
210 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800211 int nr_regs;
212 if (cpu_is_omap44xx())
213 nr_regs = OMAP4_MBOX_NR_REGS;
214 else
215 nr_regs = MBOX_NR_REGS;
216 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700217 p->ctx[i] = mbox_read_reg(i * sizeof(u32));
218
219 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
220 i, p->ctx[i]);
221 }
222}
223
224static void omap2_mbox_restore_ctx(struct omap_mbox *mbox)
225{
226 int i;
227 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800228 int nr_regs;
229 if (cpu_is_omap44xx())
230 nr_regs = OMAP4_MBOX_NR_REGS;
231 else
232 nr_regs = MBOX_NR_REGS;
233 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700234 mbox_write_reg(p->ctx[i], i * sizeof(u32));
235
236 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
237 i, p->ctx[i]);
238 }
239}
240
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800241static struct omap_mbox_ops omap2_mbox_ops = {
242 .type = OMAP_MBOX_TYPE2,
243 .startup = omap2_mbox_startup,
244 .shutdown = omap2_mbox_shutdown,
245 .fifo_read = omap2_mbox_fifo_read,
246 .fifo_write = omap2_mbox_fifo_write,
247 .fifo_empty = omap2_mbox_fifo_empty,
248 .fifo_full = omap2_mbox_fifo_full,
249 .enable_irq = omap2_mbox_enable_irq,
250 .disable_irq = omap2_mbox_disable_irq,
251 .ack_irq = omap2_mbox_ack_irq,
252 .is_irq = omap2_mbox_is_irq,
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700253 .save_ctx = omap2_mbox_save_ctx,
254 .restore_ctx = omap2_mbox_restore_ctx,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800255};
256
257/*
258 * MAILBOX 0: ARM -> DSP,
259 * MAILBOX 1: ARM <- DSP.
260 * MAILBOX 2: ARM -> IVA,
261 * MAILBOX 3: ARM <- IVA.
262 */
263
264/* FIXME: the following structs should be filled automatically by the user id */
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800265/* DSP */
266static struct omap_mbox2_priv omap2_mbox_dsp_priv = {
267 .tx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700268 .msg = MAILBOX_MESSAGE(0),
269 .fifo_stat = MAILBOX_FIFOSTATUS(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800270 },
271 .rx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700272 .msg = MAILBOX_MESSAGE(1),
273 .msg_stat = MAILBOX_MSGSTATUS(1),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800274 },
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700275 .irqenable = MAILBOX_IRQENABLE(0),
276 .irqstatus = MAILBOX_IRQSTATUS(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800277 .notfull_bit = MAILBOX_IRQ_NOTFULL(0),
278 .newmsg_bit = MAILBOX_IRQ_NEWMSG(1),
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800279 .irqdisable = MAILBOX_IRQENABLE(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800280};
281
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800282
283
284/* OMAP4 specific data structure. Use the cpu_is_omap4xxx()
285to use this*/
286static struct omap_mbox2_priv omap2_mbox_1_priv = {
287 .tx_fifo = {
288 .msg = MAILBOX_MESSAGE(0),
289 .fifo_stat = MAILBOX_FIFOSTATUS(0),
290 },
291 .rx_fifo = {
292 .msg = MAILBOX_MESSAGE(1),
293 .msg_stat = MAILBOX_MSGSTATUS(1),
294 },
295 .irqenable = OMAP4_MAILBOX_IRQENABLE(0),
296 .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0),
297 .notfull_bit = MAILBOX_IRQ_NOTFULL(0),
298 .newmsg_bit = MAILBOX_IRQ_NEWMSG(1),
299 .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0),
300};
301
302struct omap_mbox mbox_1_info = {
303 .name = "mailbox-1",
304 .ops = &omap2_mbox_ops,
305 .priv = &omap2_mbox_1_priv,
306};
307EXPORT_SYMBOL(mbox_1_info);
308
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800309struct omap_mbox mbox_dsp_info = {
310 .name = "dsp",
311 .ops = &omap2_mbox_ops,
312 .priv = &omap2_mbox_dsp_priv,
313};
314EXPORT_SYMBOL(mbox_dsp_info);
315
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800316static struct omap_mbox2_priv omap2_mbox_2_priv = {
317 .tx_fifo = {
318 .msg = MAILBOX_MESSAGE(3),
319 .fifo_stat = MAILBOX_FIFOSTATUS(3),
320 },
321 .rx_fifo = {
322 .msg = MAILBOX_MESSAGE(2),
323 .msg_stat = MAILBOX_MSGSTATUS(2),
324 },
325 .irqenable = OMAP4_MAILBOX_IRQENABLE(0),
326 .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0),
327 .notfull_bit = MAILBOX_IRQ_NOTFULL(3),
328 .newmsg_bit = MAILBOX_IRQ_NEWMSG(2),
329 .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0),
330};
331
332struct omap_mbox mbox_2_info = {
333 .name = "mailbox-2",
334 .ops = &omap2_mbox_ops,
335 .priv = &omap2_mbox_2_priv,
336};
337EXPORT_SYMBOL(mbox_2_info);
338
339
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700340#if defined(CONFIG_ARCH_OMAP2420) /* IVA */
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800341static struct omap_mbox2_priv omap2_mbox_iva_priv = {
342 .tx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700343 .msg = MAILBOX_MESSAGE(2),
344 .fifo_stat = MAILBOX_FIFOSTATUS(2),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800345 },
346 .rx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700347 .msg = MAILBOX_MESSAGE(3),
348 .msg_stat = MAILBOX_MSGSTATUS(3),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800349 },
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700350 .irqenable = MAILBOX_IRQENABLE(3),
351 .irqstatus = MAILBOX_IRQSTATUS(3),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800352 .notfull_bit = MAILBOX_IRQ_NOTFULL(2),
353 .newmsg_bit = MAILBOX_IRQ_NEWMSG(3),
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800354 .irqdisable = MAILBOX_IRQENABLE(3),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800355};
356
357static struct omap_mbox mbox_iva_info = {
358 .name = "iva",
359 .ops = &omap2_mbox_ops,
360 .priv = &omap2_mbox_iva_priv,
361};
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700362#endif
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800363
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700364static int __devinit omap2_mbox_probe(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800365{
366 struct resource *res;
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700367 int ret;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800368
369 /* MBOX base */
370 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
371 if (unlikely(!res)) {
372 dev_err(&pdev->dev, "invalid mem resource\n");
373 return -ENODEV;
374 }
Tobias Klauser6d135242009-11-10 18:55:19 -0800375 mbox_base = ioremap(res->start, resource_size(res));
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700376 if (!mbox_base)
377 return -ENOMEM;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800378
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700379 /* DSP or IVA2 IRQ */
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800380 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
381
382 if (unlikely(!res)) {
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800383 dev_err(&pdev->dev, "invalid irq resource\n");
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800384 ret = -ENODEV;
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700385 goto err_dsp;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800386 }
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800387 if (cpu_is_omap44xx()) {
388 mbox_1_info.irq = res->start;
389 ret = omap_mbox_register(&pdev->dev, &mbox_1_info);
390 } else {
391 mbox_dsp_info.irq = res->start;
392 ret = omap_mbox_register(&pdev->dev, &mbox_dsp_info);
393 }
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700394 if (ret)
395 goto err_dsp;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800396
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800397 if (cpu_is_omap44xx()) {
398 mbox_2_info.irq = res->start;
399 ret = omap_mbox_register(&pdev->dev, &mbox_2_info);
400 if (ret) {
401 omap_mbox_unregister(&mbox_1_info);
402 goto err_dsp;
403 }
404 }
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700405#if defined(CONFIG_ARCH_OMAP2420) /* IVA */
406 if (cpu_is_omap2420()) {
407 /* IVA IRQ */
408 res = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
409 if (unlikely(!res)) {
410 dev_err(&pdev->dev, "invalid irq resource\n");
411 ret = -ENODEV;
412 goto err_iva1;
413 }
414 mbox_iva_info.irq = res->start;
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700415 ret = omap_mbox_register(&pdev->dev, &mbox_iva_info);
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700416 if (ret)
417 goto err_iva1;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800418 }
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700419#endif
420 return 0;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800421
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700422err_iva1:
423 omap_mbox_unregister(&mbox_dsp_info);
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800424
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700425err_dsp:
426 iounmap(mbox_base);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800427 return ret;
428}
429
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700430static int __devexit omap2_mbox_remove(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800431{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700432#if defined(CONFIG_ARCH_OMAP2420)
433 omap_mbox_unregister(&mbox_iva_info);
434#endif
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800435
436 if (cpu_is_omap44xx()) {
437 omap_mbox_unregister(&mbox_2_info);
438 omap_mbox_unregister(&mbox_1_info);
439 } else
440 omap_mbox_unregister(&mbox_dsp_info);
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700441 iounmap(mbox_base);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800442 return 0;
443}
444
445static struct platform_driver omap2_mbox_driver = {
446 .probe = omap2_mbox_probe,
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700447 .remove = __devexit_p(omap2_mbox_remove),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800448 .driver = {
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800449 .name = DRV_NAME,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800450 },
451};
452
453static int __init omap2_mbox_init(void)
454{
455 return platform_driver_register(&omap2_mbox_driver);
456}
457
458static void __exit omap2_mbox_exit(void)
459{
460 platform_driver_unregister(&omap2_mbox_driver);
461}
462
463module_init(omap2_mbox_init);
464module_exit(omap2_mbox_exit);
465
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700466MODULE_LICENSE("GPL v2");
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800467MODULE_DESCRIPTION("omap mailbox: omap2/3/4 architecture specific functions");
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700468MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>, Paul Mundt");
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800469MODULE_ALIAS("platform:"DRV_NAME);