blob: 62d5ffe9010007302fc743a2fcff0e02070f6ca1 [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
Hiroshi DOYU733ecc52009-03-23 18:07:23 -070021#define MAILBOX_REVISION 0x000
22#define MAILBOX_SYSCONFIG 0x010
23#define MAILBOX_SYSSTATUS 0x014
24#define MAILBOX_MESSAGE(m) (0x040 + 4 * (m))
25#define MAILBOX_FIFOSTATUS(m) (0x080 + 4 * (m))
26#define MAILBOX_MSGSTATUS(m) (0x0c0 + 4 * (m))
27#define MAILBOX_IRQSTATUS(u) (0x100 + 8 * (u))
28#define MAILBOX_IRQENABLE(u) (0x104 + 8 * (u))
29
C A Subramaniam5f00ec62009-11-22 10:11:22 -080030#define OMAP4_MAILBOX_IRQSTATUS(u) (0x104 + 10 * (u))
31#define OMAP4_MAILBOX_IRQENABLE(u) (0x108 + 10 * (u))
32#define OMAP4_MAILBOX_IRQENABLE_CLR(u) (0x10c + 10 * (u))
33
34#define MAILBOX_IRQ_NEWMSG(m) (1 << (2 * (m)))
35#define MAILBOX_IRQ_NOTFULL(m) (1 << (2 * (m) + 1))
Hiroshi DOYU340a6142006-12-07 15:43:59 -080036
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070037/* SYSCONFIG: register bit definition */
38#define AUTOIDLE (1 << 0)
39#define SOFTRESET (1 << 1)
40#define SMARTIDLE (2 << 3)
Suman Annaa6a60222010-01-26 16:55:29 -060041#define OMAP4_SOFTRESET (1 << 0)
Suman Anna4499ce42010-02-05 17:20:26 -060042#define OMAP4_NOIDLE (1 << 2)
43#define OMAP4_SMARTIDLE (2 << 2)
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070044
45/* SYSSTATUS: register bit definition */
46#define RESETDONE (1 << 0)
47
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070048#define MBOX_REG_SIZE 0x120
C A Subramaniam5f00ec62009-11-22 10:11:22 -080049
50#define OMAP4_MBOX_REG_SIZE 0x130
51
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070052#define MBOX_NR_REGS (MBOX_REG_SIZE / sizeof(u32))
C A Subramaniam5f00ec62009-11-22 10:11:22 -080053#define OMAP4_MBOX_NR_REGS (OMAP4_MBOX_REG_SIZE / sizeof(u32))
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070054
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070055static void __iomem *mbox_base;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080056
Hiroshi DOYU340a6142006-12-07 15:43:59 -080057struct omap_mbox2_fifo {
58 unsigned long msg;
59 unsigned long fifo_stat;
60 unsigned long msg_stat;
61};
62
63struct omap_mbox2_priv {
64 struct omap_mbox2_fifo tx_fifo;
65 struct omap_mbox2_fifo rx_fifo;
66 unsigned long irqenable;
67 unsigned long irqstatus;
68 u32 newmsg_bit;
69 u32 notfull_bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -080070 u32 ctx[OMAP4_MBOX_NR_REGS];
71 unsigned long irqdisable;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080072};
73
74static struct clk *mbox_ick_handle;
75
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +030076static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
77 omap_mbox_type_t irq);
78
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070079static inline unsigned int mbox_read_reg(size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080080{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070081 return __raw_readl(mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080082}
83
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070084static inline void mbox_write_reg(u32 val, size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080085{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070086 __raw_writel(val, mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080087}
88
89/* Mailbox H/W preparations */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +030090static int omap2_mbox_startup(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080091{
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070092 u32 l;
93 unsigned long timeout;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080094
95 mbox_ick_handle = clk_get(NULL, "mailboxes_ick");
96 if (IS_ERR(mbox_ick_handle)) {
Felipe Balbi0cd7e1c2010-02-15 10:03:33 -080097 printk(KERN_ERR "Could not get mailboxes_ick: %ld\n",
C A Subramaniam5f00ec62009-11-22 10:11:22 -080098 PTR_ERR(mbox_ick_handle));
99 return PTR_ERR(mbox_ick_handle);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800100 }
101 clk_enable(mbox_ick_handle);
102
Suman Annaa6a60222010-01-26 16:55:29 -0600103 if (cpu_is_omap44xx()) {
104 mbox_write_reg(OMAP4_SOFTRESET, MAILBOX_SYSCONFIG);
105 timeout = jiffies + msecs_to_jiffies(20);
106 do {
107 l = mbox_read_reg(MAILBOX_SYSCONFIG);
108 if (!(l & OMAP4_SOFTRESET))
109 break;
110 } while (!time_after(jiffies, timeout));
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -0700111
Suman Annaa6a60222010-01-26 16:55:29 -0600112 if (l & OMAP4_SOFTRESET) {
113 pr_err("Can't take mailbox out of reset\n");
114 return -ENODEV;
115 }
116 } else {
117 mbox_write_reg(SOFTRESET, MAILBOX_SYSCONFIG);
118 timeout = jiffies + msecs_to_jiffies(20);
119 do {
120 l = mbox_read_reg(MAILBOX_SYSSTATUS);
121 if (l & RESETDONE)
122 break;
123 } while (!time_after(jiffies, timeout));
124
125 if (!(l & RESETDONE)) {
126 pr_err("Can't take mailbox out of reset\n");
127 return -ENODEV;
128 }
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -0700129 }
130
Hiroshi DOYU94fc58c2009-03-23 18:07:24 -0700131 l = mbox_read_reg(MAILBOX_REVISION);
Felipe Contreras909f9dc2010-06-11 15:51:37 +0000132 pr_debug("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));
Hiroshi DOYU94fc58c2009-03-23 18:07:24 -0700133
Suman Anna4499ce42010-02-05 17:20:26 -0600134 if (cpu_is_omap44xx())
135 l = OMAP4_SMARTIDLE;
136 else
137 l = SMARTIDLE | AUTOIDLE;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800138 mbox_write_reg(l, MAILBOX_SYSCONFIG);
139
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300140 omap2_mbox_enable_irq(mbox, IRQ_RX);
141
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800142 return 0;
143}
144
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300145static void omap2_mbox_shutdown(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800146{
147 clk_disable(mbox_ick_handle);
148 clk_put(mbox_ick_handle);
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800149 mbox_ick_handle = NULL;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800150}
151
152/* Mailbox FIFO handle functions */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300153static mbox_msg_t omap2_mbox_fifo_read(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800154{
155 struct omap_mbox2_fifo *fifo =
156 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
157 return (mbox_msg_t) mbox_read_reg(fifo->msg);
158}
159
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300160static void omap2_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800161{
162 struct omap_mbox2_fifo *fifo =
163 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
164 mbox_write_reg(msg, fifo->msg);
165}
166
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300167static int omap2_mbox_fifo_empty(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800168{
169 struct omap_mbox2_fifo *fifo =
170 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
171 return (mbox_read_reg(fifo->msg_stat) == 0);
172}
173
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300174static int omap2_mbox_fifo_full(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800175{
176 struct omap_mbox2_fifo *fifo =
177 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800178 return mbox_read_reg(fifo->fifo_stat);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800179}
180
181/* Mailbox IRQ handle functions */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300182static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800183 omap_mbox_type_t irq)
184{
185 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
186 u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
187
188 l = mbox_read_reg(p->irqenable);
189 l |= bit;
190 mbox_write_reg(l, p->irqenable);
191}
192
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300193static void omap2_mbox_disable_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800194 omap_mbox_type_t irq)
195{
196 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
197 u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800198 l = mbox_read_reg(p->irqdisable);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800199 l &= ~bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800200 mbox_write_reg(l, p->irqdisable);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800201}
202
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300203static void omap2_mbox_ack_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800204 omap_mbox_type_t irq)
205{
206 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
207 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
208
209 mbox_write_reg(bit, p->irqstatus);
Hiroshi DOYU88288802009-09-24 16:23:10 -0700210
211 /* Flush posted write for irq status to avoid spurious interrupts */
212 mbox_read_reg(p->irqstatus);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800213}
214
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300215static int omap2_mbox_is_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800216 omap_mbox_type_t irq)
217{
218 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
219 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
220 u32 enable = mbox_read_reg(p->irqenable);
221 u32 status = mbox_read_reg(p->irqstatus);
222
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800223 return (int)(enable & status & bit);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800224}
225
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700226static void omap2_mbox_save_ctx(struct omap_mbox *mbox)
227{
228 int i;
229 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800230 int nr_regs;
231 if (cpu_is_omap44xx())
232 nr_regs = OMAP4_MBOX_NR_REGS;
233 else
234 nr_regs = MBOX_NR_REGS;
235 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700236 p->ctx[i] = mbox_read_reg(i * sizeof(u32));
237
238 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
239 i, p->ctx[i]);
240 }
241}
242
243static void omap2_mbox_restore_ctx(struct omap_mbox *mbox)
244{
245 int i;
246 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800247 int nr_regs;
248 if (cpu_is_omap44xx())
249 nr_regs = OMAP4_MBOX_NR_REGS;
250 else
251 nr_regs = MBOX_NR_REGS;
252 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700253 mbox_write_reg(p->ctx[i], i * sizeof(u32));
254
255 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
256 i, p->ctx[i]);
257 }
258}
259
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800260static struct omap_mbox_ops omap2_mbox_ops = {
261 .type = OMAP_MBOX_TYPE2,
262 .startup = omap2_mbox_startup,
263 .shutdown = omap2_mbox_shutdown,
264 .fifo_read = omap2_mbox_fifo_read,
265 .fifo_write = omap2_mbox_fifo_write,
266 .fifo_empty = omap2_mbox_fifo_empty,
267 .fifo_full = omap2_mbox_fifo_full,
268 .enable_irq = omap2_mbox_enable_irq,
269 .disable_irq = omap2_mbox_disable_irq,
270 .ack_irq = omap2_mbox_ack_irq,
271 .is_irq = omap2_mbox_is_irq,
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700272 .save_ctx = omap2_mbox_save_ctx,
273 .restore_ctx = omap2_mbox_restore_ctx,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800274};
275
276/*
277 * MAILBOX 0: ARM -> DSP,
278 * MAILBOX 1: ARM <- DSP.
279 * MAILBOX 2: ARM -> IVA,
280 * MAILBOX 3: ARM <- IVA.
281 */
282
283/* FIXME: the following structs should be filled automatically by the user id */
Felipe Contreras07d65d82010-06-11 15:51:38 +0000284
Felipe Contreras14476bd2010-06-11 15:51:47 +0000285#if defined(CONFIG_ARCH_OMAP3430) || defined(CONFIG_ARCH_OMAP2420)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800286/* DSP */
287static struct omap_mbox2_priv omap2_mbox_dsp_priv = {
288 .tx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700289 .msg = MAILBOX_MESSAGE(0),
290 .fifo_stat = MAILBOX_FIFOSTATUS(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800291 },
292 .rx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700293 .msg = MAILBOX_MESSAGE(1),
294 .msg_stat = MAILBOX_MSGSTATUS(1),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800295 },
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700296 .irqenable = MAILBOX_IRQENABLE(0),
297 .irqstatus = MAILBOX_IRQSTATUS(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800298 .notfull_bit = MAILBOX_IRQ_NOTFULL(0),
299 .newmsg_bit = MAILBOX_IRQ_NEWMSG(1),
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800300 .irqdisable = MAILBOX_IRQENABLE(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800301};
302
Felipe Contreras07d65d82010-06-11 15:51:38 +0000303struct omap_mbox mbox_dsp_info = {
304 .name = "dsp",
305 .ops = &omap2_mbox_ops,
306 .priv = &omap2_mbox_dsp_priv,
307};
Felipe Contreras14476bd2010-06-11 15:51:47 +0000308#endif
Felipe Contreras07d65d82010-06-11 15:51:38 +0000309
Felipe Contreras14476bd2010-06-11 15:51:47 +0000310#if defined(CONFIG_ARCH_OMAP3430)
Felipe Contreras898ee752010-06-11 15:51:45 +0000311struct omap_mbox *omap3_mboxes[] = { &mbox_dsp_info, NULL };
Felipe Contreras14476bd2010-06-11 15:51:47 +0000312#endif
Felipe Contreras898ee752010-06-11 15:51:45 +0000313
Felipe Contreras07d65d82010-06-11 15:51:38 +0000314#if defined(CONFIG_ARCH_OMAP2420)
Felipe Contreras07d65d82010-06-11 15:51:38 +0000315/* IVA */
316static struct omap_mbox2_priv omap2_mbox_iva_priv = {
317 .tx_fifo = {
318 .msg = MAILBOX_MESSAGE(2),
319 .fifo_stat = MAILBOX_FIFOSTATUS(2),
320 },
321 .rx_fifo = {
322 .msg = MAILBOX_MESSAGE(3),
323 .msg_stat = MAILBOX_MSGSTATUS(3),
324 },
325 .irqenable = MAILBOX_IRQENABLE(3),
326 .irqstatus = MAILBOX_IRQSTATUS(3),
327 .notfull_bit = MAILBOX_IRQ_NOTFULL(2),
328 .newmsg_bit = MAILBOX_IRQ_NEWMSG(3),
329 .irqdisable = MAILBOX_IRQENABLE(3),
330};
331
332static struct omap_mbox mbox_iva_info = {
333 .name = "iva",
334 .ops = &omap2_mbox_ops,
335 .priv = &omap2_mbox_iva_priv,
336};
Felipe Contreras898ee752010-06-11 15:51:45 +0000337
338struct omap_mbox *omap2_mboxes[] = { &mbox_iva_info, &mbox_dsp_info, NULL };
Felipe Contreras07d65d82010-06-11 15:51:38 +0000339#endif
340
Felipe Contreras14476bd2010-06-11 15:51:47 +0000341#if defined(CONFIG_ARCH_OMAP4)
Felipe Contreras07d65d82010-06-11 15:51:38 +0000342/* OMAP4 */
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800343static struct omap_mbox2_priv omap2_mbox_1_priv = {
344 .tx_fifo = {
345 .msg = MAILBOX_MESSAGE(0),
346 .fifo_stat = MAILBOX_FIFOSTATUS(0),
347 },
348 .rx_fifo = {
349 .msg = MAILBOX_MESSAGE(1),
350 .msg_stat = MAILBOX_MSGSTATUS(1),
351 },
352 .irqenable = OMAP4_MAILBOX_IRQENABLE(0),
353 .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0),
354 .notfull_bit = MAILBOX_IRQ_NOTFULL(0),
355 .newmsg_bit = MAILBOX_IRQ_NEWMSG(1),
356 .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0),
357};
358
359struct omap_mbox mbox_1_info = {
360 .name = "mailbox-1",
361 .ops = &omap2_mbox_ops,
362 .priv = &omap2_mbox_1_priv,
363};
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800364
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800365static struct omap_mbox2_priv omap2_mbox_2_priv = {
366 .tx_fifo = {
367 .msg = MAILBOX_MESSAGE(3),
368 .fifo_stat = MAILBOX_FIFOSTATUS(3),
369 },
370 .rx_fifo = {
371 .msg = MAILBOX_MESSAGE(2),
372 .msg_stat = MAILBOX_MSGSTATUS(2),
373 },
374 .irqenable = OMAP4_MAILBOX_IRQENABLE(0),
375 .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0),
376 .notfull_bit = MAILBOX_IRQ_NOTFULL(3),
377 .newmsg_bit = MAILBOX_IRQ_NEWMSG(2),
378 .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0),
379};
380
381struct omap_mbox mbox_2_info = {
382 .name = "mailbox-2",
383 .ops = &omap2_mbox_ops,
384 .priv = &omap2_mbox_2_priv,
385};
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800386
Felipe Contreras898ee752010-06-11 15:51:45 +0000387struct omap_mbox *omap4_mboxes[] = { &mbox_1_info, &mbox_2_info, NULL };
Felipe Contreras14476bd2010-06-11 15:51:47 +0000388#endif
Felipe Contreras898ee752010-06-11 15:51:45 +0000389
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700390static int __devinit omap2_mbox_probe(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800391{
Felipe Contreras898ee752010-06-11 15:51:45 +0000392 struct resource *mem;
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700393 int ret;
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000394 struct omap_mbox **list;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800395
Felipe Contreras14476bd2010-06-11 15:51:47 +0000396 if (false)
397 ;
398#if defined(CONFIG_ARCH_OMAP3430)
399 else if (cpu_is_omap3430()) {
Felipe Contreras898ee752010-06-11 15:51:45 +0000400 list = omap3_mboxes;
401
402 list[0]->irq = platform_get_irq_byname(pdev, "dsp");
403 }
Felipe Contreras14476bd2010-06-11 15:51:47 +0000404#endif
Felipe Contreras898ee752010-06-11 15:51:45 +0000405#if defined(CONFIG_ARCH_OMAP2420)
406 else if (cpu_is_omap2420()) {
407 list = omap2_mboxes;
408
409 list[0]->irq = platform_get_irq_byname(pdev, "dsp");
410 list[1]->irq = platform_get_irq_byname(pdev, "iva");
411 }
412#endif
Felipe Contreras14476bd2010-06-11 15:51:47 +0000413#if defined(CONFIG_ARCH_OMAP4)
Felipe Contreras898ee752010-06-11 15:51:45 +0000414 else if (cpu_is_omap44xx()) {
415 list = omap4_mboxes;
416
417 list[0]->irq = list[1]->irq =
418 platform_get_irq_byname(pdev, "mbox");
419 }
Felipe Contreras14476bd2010-06-11 15:51:47 +0000420#endif
Felipe Contreras898ee752010-06-11 15:51:45 +0000421 else {
422 pr_err("%s: platform not supported\n", __func__);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800423 return -ENODEV;
424 }
Felipe Contreras898ee752010-06-11 15:51:45 +0000425
426 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
427 mbox_base = ioremap(mem->start, resource_size(mem));
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700428 if (!mbox_base)
429 return -ENOMEM;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800430
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000431 ret = omap_mbox_register(&pdev->dev, list);
432 if (ret) {
433 iounmap(mbox_base);
434 return ret;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800435 }
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700436 return 0;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800437
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800438 return ret;
439}
440
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700441static int __devexit omap2_mbox_remove(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800442{
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000443 omap_mbox_unregister();
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700444 iounmap(mbox_base);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800445 return 0;
446}
447
448static struct platform_driver omap2_mbox_driver = {
449 .probe = omap2_mbox_probe,
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700450 .remove = __devexit_p(omap2_mbox_remove),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800451 .driver = {
Felipe Contrerasd7427092010-06-11 15:51:48 +0000452 .name = "omap-mailbox",
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800453 },
454};
455
456static int __init omap2_mbox_init(void)
457{
458 return platform_driver_register(&omap2_mbox_driver);
459}
460
461static void __exit omap2_mbox_exit(void)
462{
463 platform_driver_unregister(&omap2_mbox_driver);
464}
465
466module_init(omap2_mbox_init);
467module_exit(omap2_mbox_exit);
468
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700469MODULE_LICENSE("GPL v2");
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800470MODULE_DESCRIPTION("omap mailbox: omap2/3/4 architecture specific functions");
Ohad Ben-Cohenf3753252010-05-05 15:33:07 +0000471MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
472MODULE_AUTHOR("Paul Mundt");
Felipe Contrerasd7427092010-06-11 15:51:48 +0000473MODULE_ALIAS("platform:omap2-mailbox");