blob: edcfec6ff67b4b69572c0c239552fb6438c35a0c [file] [log] [blame]
Hiroshi DOYU340a614a2006-12-07 15:43:59 -08001/*
Hiroshi DOYU733ecc52009-03-23 18:07:23 -07002 * Mailbox reservation modules for OMAP2/3
Hiroshi DOYU340a614a2006-12-07 15:43:59 -08003 *
Hiroshi DOYU733ecc52009-03-23 18:07:23 -07004 * Copyright (C) 2006-2009 Nokia Corporation
Hiroshi DOYU340a614a2006-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 DOYU340a614a2006-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 DOYU340a614a2006-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 DOYU340a614a2006-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)
Suman Annaa6a60222010-01-26 16:55:29 -060043#define OMAP4_SOFTRESET (1 << 0)
Suman Anna4499ce42010-02-05 17:20:26 -060044#define OMAP4_NOIDLE (1 << 2)
45#define OMAP4_SMARTIDLE (2 << 2)
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070046
47/* SYSSTATUS: register bit definition */
48#define RESETDONE (1 << 0)
49
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070050#define MBOX_REG_SIZE 0x120
C A Subramaniam5f00ec62009-11-22 10:11:22 -080051
52#define OMAP4_MBOX_REG_SIZE 0x130
53
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070054#define MBOX_NR_REGS (MBOX_REG_SIZE / sizeof(u32))
C A Subramaniam5f00ec62009-11-22 10:11:22 -080055#define OMAP4_MBOX_NR_REGS (OMAP4_MBOX_REG_SIZE / sizeof(u32))
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070056
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070057static void __iomem *mbox_base;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080058
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080059struct omap_mbox2_fifo {
60 unsigned long msg;
61 unsigned long fifo_stat;
62 unsigned long msg_stat;
63};
64
65struct omap_mbox2_priv {
66 struct omap_mbox2_fifo tx_fifo;
67 struct omap_mbox2_fifo rx_fifo;
68 unsigned long irqenable;
69 unsigned long irqstatus;
70 u32 newmsg_bit;
71 u32 notfull_bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -080072 u32 ctx[OMAP4_MBOX_NR_REGS];
73 unsigned long irqdisable;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080074};
75
76static struct clk *mbox_ick_handle;
77
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +030078static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
79 omap_mbox_type_t irq);
80
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070081static inline unsigned int mbox_read_reg(size_t ofs)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080082{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070083 return __raw_readl(mbox_base + ofs);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080084}
85
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070086static inline void mbox_write_reg(u32 val, size_t ofs)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080087{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070088 __raw_writel(val, mbox_base + ofs);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080089}
90
91/* Mailbox H/W preparations */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +030092static int omap2_mbox_startup(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080093{
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070094 u32 l;
95 unsigned long timeout;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080096
97 mbox_ick_handle = clk_get(NULL, "mailboxes_ick");
98 if (IS_ERR(mbox_ick_handle)) {
Felipe Balbi0cd7e1c2010-02-15 10:03:33 -080099 printk(KERN_ERR "Could not get mailboxes_ick: %ld\n",
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800100 PTR_ERR(mbox_ick_handle));
101 return PTR_ERR(mbox_ick_handle);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800102 }
103 clk_enable(mbox_ick_handle);
104
Suman Annaa6a60222010-01-26 16:55:29 -0600105 if (cpu_is_omap44xx()) {
106 mbox_write_reg(OMAP4_SOFTRESET, MAILBOX_SYSCONFIG);
107 timeout = jiffies + msecs_to_jiffies(20);
108 do {
109 l = mbox_read_reg(MAILBOX_SYSCONFIG);
110 if (!(l & OMAP4_SOFTRESET))
111 break;
112 } while (!time_after(jiffies, timeout));
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -0700113
Suman Annaa6a60222010-01-26 16:55:29 -0600114 if (l & OMAP4_SOFTRESET) {
115 pr_err("Can't take mailbox out of reset\n");
116 return -ENODEV;
117 }
118 } else {
119 mbox_write_reg(SOFTRESET, MAILBOX_SYSCONFIG);
120 timeout = jiffies + msecs_to_jiffies(20);
121 do {
122 l = mbox_read_reg(MAILBOX_SYSSTATUS);
123 if (l & RESETDONE)
124 break;
125 } while (!time_after(jiffies, timeout));
126
127 if (!(l & RESETDONE)) {
128 pr_err("Can't take mailbox out of reset\n");
129 return -ENODEV;
130 }
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -0700131 }
132
Hiroshi DOYU94fc58c2009-03-23 18:07:24 -0700133 l = mbox_read_reg(MAILBOX_REVISION);
Felipe Contreras909f9dc2010-06-11 15:51:37 +0000134 pr_debug("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));
Hiroshi DOYU94fc58c2009-03-23 18:07:24 -0700135
Suman Anna4499ce42010-02-05 17:20:26 -0600136 if (cpu_is_omap44xx())
137 l = OMAP4_SMARTIDLE;
138 else
139 l = SMARTIDLE | AUTOIDLE;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800140 mbox_write_reg(l, MAILBOX_SYSCONFIG);
141
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300142 omap2_mbox_enable_irq(mbox, IRQ_RX);
143
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800144 return 0;
145}
146
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300147static void omap2_mbox_shutdown(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800148{
149 clk_disable(mbox_ick_handle);
150 clk_put(mbox_ick_handle);
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800151 mbox_ick_handle = NULL;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800152}
153
154/* Mailbox FIFO handle functions */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300155static mbox_msg_t omap2_mbox_fifo_read(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800156{
157 struct omap_mbox2_fifo *fifo =
158 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
159 return (mbox_msg_t) mbox_read_reg(fifo->msg);
160}
161
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300162static void omap2_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800163{
164 struct omap_mbox2_fifo *fifo =
165 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
166 mbox_write_reg(msg, fifo->msg);
167}
168
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300169static int omap2_mbox_fifo_empty(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800170{
171 struct omap_mbox2_fifo *fifo =
172 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
173 return (mbox_read_reg(fifo->msg_stat) == 0);
174}
175
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300176static int omap2_mbox_fifo_full(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800177{
178 struct omap_mbox2_fifo *fifo =
179 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800180 return mbox_read_reg(fifo->fifo_stat);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800181}
182
183/* Mailbox IRQ handle functions */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300184static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a614a2006-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 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
189
190 l = mbox_read_reg(p->irqenable);
191 l |= bit;
192 mbox_write_reg(l, p->irqenable);
193}
194
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300195static void omap2_mbox_disable_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800196 omap_mbox_type_t irq)
197{
198 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
199 u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800200 l = mbox_read_reg(p->irqdisable);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800201 l &= ~bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800202 mbox_write_reg(l, p->irqdisable);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800203}
204
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300205static void omap2_mbox_ack_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800206 omap_mbox_type_t irq)
207{
208 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
209 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
210
211 mbox_write_reg(bit, p->irqstatus);
Hiroshi DOYU88288802009-09-24 16:23:10 -0700212
213 /* Flush posted write for irq status to avoid spurious interrupts */
214 mbox_read_reg(p->irqstatus);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800215}
216
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300217static int omap2_mbox_is_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800218 omap_mbox_type_t irq)
219{
220 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
221 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
222 u32 enable = mbox_read_reg(p->irqenable);
223 u32 status = mbox_read_reg(p->irqstatus);
224
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800225 return (int)(enable & status & bit);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800226}
227
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700228static void omap2_mbox_save_ctx(struct omap_mbox *mbox)
229{
230 int i;
231 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800232 int nr_regs;
233 if (cpu_is_omap44xx())
234 nr_regs = OMAP4_MBOX_NR_REGS;
235 else
236 nr_regs = MBOX_NR_REGS;
237 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700238 p->ctx[i] = mbox_read_reg(i * sizeof(u32));
239
240 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
241 i, p->ctx[i]);
242 }
243}
244
245static void omap2_mbox_restore_ctx(struct omap_mbox *mbox)
246{
247 int i;
248 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800249 int nr_regs;
250 if (cpu_is_omap44xx())
251 nr_regs = OMAP4_MBOX_NR_REGS;
252 else
253 nr_regs = MBOX_NR_REGS;
254 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700255 mbox_write_reg(p->ctx[i], i * sizeof(u32));
256
257 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
258 i, p->ctx[i]);
259 }
260}
261
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800262static struct omap_mbox_ops omap2_mbox_ops = {
263 .type = OMAP_MBOX_TYPE2,
264 .startup = omap2_mbox_startup,
265 .shutdown = omap2_mbox_shutdown,
266 .fifo_read = omap2_mbox_fifo_read,
267 .fifo_write = omap2_mbox_fifo_write,
268 .fifo_empty = omap2_mbox_fifo_empty,
269 .fifo_full = omap2_mbox_fifo_full,
270 .enable_irq = omap2_mbox_enable_irq,
271 .disable_irq = omap2_mbox_disable_irq,
272 .ack_irq = omap2_mbox_ack_irq,
273 .is_irq = omap2_mbox_is_irq,
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700274 .save_ctx = omap2_mbox_save_ctx,
275 .restore_ctx = omap2_mbox_restore_ctx,
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800276};
277
278/*
279 * MAILBOX 0: ARM -> DSP,
280 * MAILBOX 1: ARM <- DSP.
281 * MAILBOX 2: ARM -> IVA,
282 * MAILBOX 3: ARM <- IVA.
283 */
284
285/* FIXME: the following structs should be filled automatically by the user id */
Felipe Contreras07d65d82010-06-11 15:51:38 +0000286
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800287/* DSP */
288static struct omap_mbox2_priv omap2_mbox_dsp_priv = {
289 .tx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700290 .msg = MAILBOX_MESSAGE(0),
291 .fifo_stat = MAILBOX_FIFOSTATUS(0),
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800292 },
293 .rx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700294 .msg = MAILBOX_MESSAGE(1),
295 .msg_stat = MAILBOX_MSGSTATUS(1),
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800296 },
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700297 .irqenable = MAILBOX_IRQENABLE(0),
298 .irqstatus = MAILBOX_IRQSTATUS(0),
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800299 .notfull_bit = MAILBOX_IRQ_NOTFULL(0),
300 .newmsg_bit = MAILBOX_IRQ_NEWMSG(1),
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800301 .irqdisable = MAILBOX_IRQENABLE(0),
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800302};
303
Felipe Contreras07d65d82010-06-11 15:51:38 +0000304struct omap_mbox mbox_dsp_info = {
305 .name = "dsp",
306 .ops = &omap2_mbox_ops,
307 .priv = &omap2_mbox_dsp_priv,
308};
309EXPORT_SYMBOL(mbox_dsp_info);
310
311#if defined(CONFIG_ARCH_OMAP2420)
312
313/* IVA */
314static struct omap_mbox2_priv omap2_mbox_iva_priv = {
315 .tx_fifo = {
316 .msg = MAILBOX_MESSAGE(2),
317 .fifo_stat = MAILBOX_FIFOSTATUS(2),
318 },
319 .rx_fifo = {
320 .msg = MAILBOX_MESSAGE(3),
321 .msg_stat = MAILBOX_MSGSTATUS(3),
322 },
323 .irqenable = MAILBOX_IRQENABLE(3),
324 .irqstatus = MAILBOX_IRQSTATUS(3),
325 .notfull_bit = MAILBOX_IRQ_NOTFULL(2),
326 .newmsg_bit = MAILBOX_IRQ_NEWMSG(3),
327 .irqdisable = MAILBOX_IRQENABLE(3),
328};
329
330static struct omap_mbox mbox_iva_info = {
331 .name = "iva",
332 .ops = &omap2_mbox_ops,
333 .priv = &omap2_mbox_iva_priv,
334};
335#endif
336
337/* OMAP4 */
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800338static struct omap_mbox2_priv omap2_mbox_1_priv = {
339 .tx_fifo = {
340 .msg = MAILBOX_MESSAGE(0),
341 .fifo_stat = MAILBOX_FIFOSTATUS(0),
342 },
343 .rx_fifo = {
344 .msg = MAILBOX_MESSAGE(1),
345 .msg_stat = MAILBOX_MSGSTATUS(1),
346 },
347 .irqenable = OMAP4_MAILBOX_IRQENABLE(0),
348 .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0),
349 .notfull_bit = MAILBOX_IRQ_NOTFULL(0),
350 .newmsg_bit = MAILBOX_IRQ_NEWMSG(1),
351 .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0),
352};
353
354struct omap_mbox mbox_1_info = {
355 .name = "mailbox-1",
356 .ops = &omap2_mbox_ops,
357 .priv = &omap2_mbox_1_priv,
358};
359EXPORT_SYMBOL(mbox_1_info);
360
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800361static struct omap_mbox2_priv omap2_mbox_2_priv = {
362 .tx_fifo = {
363 .msg = MAILBOX_MESSAGE(3),
364 .fifo_stat = MAILBOX_FIFOSTATUS(3),
365 },
366 .rx_fifo = {
367 .msg = MAILBOX_MESSAGE(2),
368 .msg_stat = MAILBOX_MSGSTATUS(2),
369 },
370 .irqenable = OMAP4_MAILBOX_IRQENABLE(0),
371 .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0),
372 .notfull_bit = MAILBOX_IRQ_NOTFULL(3),
373 .newmsg_bit = MAILBOX_IRQ_NEWMSG(2),
374 .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0),
375};
376
377struct omap_mbox mbox_2_info = {
378 .name = "mailbox-2",
379 .ops = &omap2_mbox_ops,
380 .priv = &omap2_mbox_2_priv,
381};
382EXPORT_SYMBOL(mbox_2_info);
383
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700384static int __devinit omap2_mbox_probe(struct platform_device *pdev)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800385{
386 struct resource *res;
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700387 int ret;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800388
389 /* MBOX base */
390 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
391 if (unlikely(!res)) {
392 dev_err(&pdev->dev, "invalid mem resource\n");
393 return -ENODEV;
394 }
Tobias Klauser6d135242009-11-10 18:55:19 -0800395 mbox_base = ioremap(res->start, resource_size(res));
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700396 if (!mbox_base)
397 return -ENOMEM;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800398
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700399 /* DSP or IVA2 IRQ */
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800400 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
401
402 if (unlikely(!res)) {
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800403 dev_err(&pdev->dev, "invalid irq resource\n");
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800404 ret = -ENODEV;
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700405 goto err_dsp;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800406 }
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800407 if (cpu_is_omap44xx()) {
408 mbox_1_info.irq = res->start;
409 ret = omap_mbox_register(&pdev->dev, &mbox_1_info);
410 } else {
411 mbox_dsp_info.irq = res->start;
412 ret = omap_mbox_register(&pdev->dev, &mbox_dsp_info);
413 }
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700414 if (ret)
415 goto err_dsp;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800416
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800417 if (cpu_is_omap44xx()) {
418 mbox_2_info.irq = res->start;
419 ret = omap_mbox_register(&pdev->dev, &mbox_2_info);
420 if (ret) {
421 omap_mbox_unregister(&mbox_1_info);
422 goto err_dsp;
423 }
424 }
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700425#if defined(CONFIG_ARCH_OMAP2420) /* IVA */
426 if (cpu_is_omap2420()) {
427 /* IVA IRQ */
428 res = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
429 if (unlikely(!res)) {
430 dev_err(&pdev->dev, "invalid irq resource\n");
431 ret = -ENODEV;
Suman Anna26e42482010-01-25 18:27:21 -0600432 omap_mbox_unregister(&mbox_dsp_info);
433 goto err_dsp;
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700434 }
435 mbox_iva_info.irq = res->start;
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700436 ret = omap_mbox_register(&pdev->dev, &mbox_iva_info);
Suman Anna26e42482010-01-25 18:27:21 -0600437 if (ret) {
438 omap_mbox_unregister(&mbox_dsp_info);
439 goto err_dsp;
440 }
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800441 }
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700442#endif
443 return 0;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800444
Felipe Contreras909f9dc2010-06-11 15:51:37 +0000445#if defined(CONFIG_ARCH_OMAP2420) /* IVA */
446err_iva1:
447 omap_mbox_unregister(&mbox_dsp_info);
448#endif
449
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700450err_dsp:
451 iounmap(mbox_base);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800452 return ret;
453}
454
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700455static int __devexit omap2_mbox_remove(struct platform_device *pdev)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800456{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700457#if defined(CONFIG_ARCH_OMAP2420)
458 omap_mbox_unregister(&mbox_iva_info);
459#endif
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800460
461 if (cpu_is_omap44xx()) {
462 omap_mbox_unregister(&mbox_2_info);
463 omap_mbox_unregister(&mbox_1_info);
464 } else
465 omap_mbox_unregister(&mbox_dsp_info);
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700466 iounmap(mbox_base);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800467 return 0;
468}
469
470static struct platform_driver omap2_mbox_driver = {
471 .probe = omap2_mbox_probe,
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700472 .remove = __devexit_p(omap2_mbox_remove),
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800473 .driver = {
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800474 .name = DRV_NAME,
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800475 },
476};
477
478static int __init omap2_mbox_init(void)
479{
480 return platform_driver_register(&omap2_mbox_driver);
481}
482
483static void __exit omap2_mbox_exit(void)
484{
485 platform_driver_unregister(&omap2_mbox_driver);
486}
487
488module_init(omap2_mbox_init);
489module_exit(omap2_mbox_exit);
490
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700491MODULE_LICENSE("GPL v2");
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800492MODULE_DESCRIPTION("omap mailbox: omap2/3/4 architecture specific functions");
Ohad Ben-Cohenf3753252010-05-05 15:33:07 +0000493MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
494MODULE_AUTHOR("Paul Mundt");
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800495MODULE_ALIAS("platform:"DRV_NAME);