blob: 394413dc7deb59dbdb982cc40a0eb8be05dff8bc [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
Hiroshi DOYU340a6142006-12-07 15:43:59 -080013#include <linux/clk.h>
14#include <linux/err.h>
15#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010016#include <linux/io.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070017#include <plat/mailbox.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010018#include <mach/irqs.h>
Hiroshi DOYU340a6142006-12-07 15:43:59 -080019
Hiroshi DOYU733ecc52009-03-23 18:07:23 -070020#define MAILBOX_REVISION 0x000
21#define MAILBOX_SYSCONFIG 0x010
22#define MAILBOX_SYSSTATUS 0x014
23#define MAILBOX_MESSAGE(m) (0x040 + 4 * (m))
24#define MAILBOX_FIFOSTATUS(m) (0x080 + 4 * (m))
25#define MAILBOX_MSGSTATUS(m) (0x0c0 + 4 * (m))
26#define MAILBOX_IRQSTATUS(u) (0x100 + 8 * (u))
27#define MAILBOX_IRQENABLE(u) (0x104 + 8 * (u))
28
C A Subramaniam5f00ec62009-11-22 10:11:22 -080029#define OMAP4_MAILBOX_IRQSTATUS(u) (0x104 + 10 * (u))
30#define OMAP4_MAILBOX_IRQENABLE(u) (0x108 + 10 * (u))
31#define OMAP4_MAILBOX_IRQENABLE_CLR(u) (0x10c + 10 * (u))
32
33#define MAILBOX_IRQ_NEWMSG(m) (1 << (2 * (m)))
34#define MAILBOX_IRQ_NOTFULL(m) (1 << (2 * (m) + 1))
Hiroshi DOYU340a6142006-12-07 15:43:59 -080035
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070036/* SYSCONFIG: register bit definition */
37#define AUTOIDLE (1 << 0)
38#define SOFTRESET (1 << 1)
39#define SMARTIDLE (2 << 3)
Suman Annaa6a60222010-01-26 16:55:29 -060040#define OMAP4_SOFTRESET (1 << 0)
Suman Anna4499ce42010-02-05 17:20:26 -060041#define OMAP4_NOIDLE (1 << 2)
42#define OMAP4_SMARTIDLE (2 << 2)
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070043
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)) {
Felipe Balbi0cd7e1c2010-02-15 10:03:33 -080096 printk(KERN_ERR "Could not get mailboxes_ick: %ld\n",
C A Subramaniam5f00ec62009-11-22 10:11:22 -080097 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
Suman Annaa6a60222010-01-26 16:55:29 -0600102 if (cpu_is_omap44xx()) {
103 mbox_write_reg(OMAP4_SOFTRESET, MAILBOX_SYSCONFIG);
104 timeout = jiffies + msecs_to_jiffies(20);
105 do {
106 l = mbox_read_reg(MAILBOX_SYSCONFIG);
107 if (!(l & OMAP4_SOFTRESET))
108 break;
109 } while (!time_after(jiffies, timeout));
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -0700110
Suman Annaa6a60222010-01-26 16:55:29 -0600111 if (l & OMAP4_SOFTRESET) {
112 pr_err("Can't take mailbox out of reset\n");
113 return -ENODEV;
114 }
115 } else {
116 mbox_write_reg(SOFTRESET, MAILBOX_SYSCONFIG);
117 timeout = jiffies + msecs_to_jiffies(20);
118 do {
119 l = mbox_read_reg(MAILBOX_SYSSTATUS);
120 if (l & RESETDONE)
121 break;
122 } while (!time_after(jiffies, timeout));
123
124 if (!(l & RESETDONE)) {
125 pr_err("Can't take mailbox out of reset\n");
126 return -ENODEV;
127 }
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -0700128 }
129
Hiroshi DOYU94fc58c2009-03-23 18:07:24 -0700130 l = mbox_read_reg(MAILBOX_REVISION);
Felipe Contreras909f9dc2010-06-11 15:51:37 +0000131 pr_debug("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));
Hiroshi DOYU94fc58c2009-03-23 18:07:24 -0700132
Suman Anna4499ce42010-02-05 17:20:26 -0600133 if (cpu_is_omap44xx())
134 l = OMAP4_SMARTIDLE;
135 else
136 l = SMARTIDLE | AUTOIDLE;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800137 mbox_write_reg(l, MAILBOX_SYSCONFIG);
138
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300139 omap2_mbox_enable_irq(mbox, IRQ_RX);
140
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800141 return 0;
142}
143
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300144static void omap2_mbox_shutdown(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800145{
146 clk_disable(mbox_ick_handle);
147 clk_put(mbox_ick_handle);
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800148 mbox_ick_handle = NULL;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800149}
150
151/* Mailbox FIFO handle functions */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300152static mbox_msg_t omap2_mbox_fifo_read(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800153{
154 struct omap_mbox2_fifo *fifo =
155 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
156 return (mbox_msg_t) mbox_read_reg(fifo->msg);
157}
158
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300159static void omap2_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800160{
161 struct omap_mbox2_fifo *fifo =
162 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
163 mbox_write_reg(msg, fifo->msg);
164}
165
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300166static int omap2_mbox_fifo_empty(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800167{
168 struct omap_mbox2_fifo *fifo =
169 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
170 return (mbox_read_reg(fifo->msg_stat) == 0);
171}
172
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300173static int omap2_mbox_fifo_full(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800174{
175 struct omap_mbox2_fifo *fifo =
176 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800177 return mbox_read_reg(fifo->fifo_stat);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800178}
179
180/* Mailbox IRQ handle functions */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300181static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800182 omap_mbox_type_t irq)
183{
matt mooneyb45b5012010-09-27 19:04:32 -0700184 struct omap_mbox2_priv *p = mbox->priv;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800185 u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
186
187 l = mbox_read_reg(p->irqenable);
188 l |= bit;
189 mbox_write_reg(l, p->irqenable);
190}
191
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300192static void omap2_mbox_disable_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800193 omap_mbox_type_t irq)
194{
matt mooneyb45b5012010-09-27 19:04:32 -0700195 struct omap_mbox2_priv *p = mbox->priv;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800196 u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800197 l = mbox_read_reg(p->irqdisable);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800198 l &= ~bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800199 mbox_write_reg(l, p->irqdisable);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800200}
201
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300202static void omap2_mbox_ack_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800203 omap_mbox_type_t irq)
204{
matt mooneyb45b5012010-09-27 19:04:32 -0700205 struct omap_mbox2_priv *p = mbox->priv;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800206 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
207
208 mbox_write_reg(bit, p->irqstatus);
Hiroshi DOYU88288802009-09-24 16:23:10 -0700209
210 /* Flush posted write for irq status to avoid spurious interrupts */
211 mbox_read_reg(p->irqstatus);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800212}
213
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300214static int omap2_mbox_is_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800215 omap_mbox_type_t irq)
216{
matt mooneyb45b5012010-09-27 19:04:32 -0700217 struct omap_mbox2_priv *p = mbox->priv;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800218 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
219 u32 enable = mbox_read_reg(p->irqenable);
220 u32 status = mbox_read_reg(p->irqstatus);
221
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800222 return (int)(enable & status & bit);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800223}
224
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700225static void omap2_mbox_save_ctx(struct omap_mbox *mbox)
226{
227 int i;
228 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800229 int nr_regs;
230 if (cpu_is_omap44xx())
231 nr_regs = OMAP4_MBOX_NR_REGS;
232 else
233 nr_regs = MBOX_NR_REGS;
234 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700235 p->ctx[i] = mbox_read_reg(i * sizeof(u32));
236
237 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
238 i, p->ctx[i]);
239 }
240}
241
242static void omap2_mbox_restore_ctx(struct omap_mbox *mbox)
243{
244 int i;
245 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800246 int nr_regs;
247 if (cpu_is_omap44xx())
248 nr_regs = OMAP4_MBOX_NR_REGS;
249 else
250 nr_regs = MBOX_NR_REGS;
251 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700252 mbox_write_reg(p->ctx[i], i * sizeof(u32));
253
254 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
255 i, p->ctx[i]);
256 }
257}
258
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800259static struct omap_mbox_ops omap2_mbox_ops = {
260 .type = OMAP_MBOX_TYPE2,
261 .startup = omap2_mbox_startup,
262 .shutdown = omap2_mbox_shutdown,
263 .fifo_read = omap2_mbox_fifo_read,
264 .fifo_write = omap2_mbox_fifo_write,
265 .fifo_empty = omap2_mbox_fifo_empty,
266 .fifo_full = omap2_mbox_fifo_full,
267 .enable_irq = omap2_mbox_enable_irq,
268 .disable_irq = omap2_mbox_disable_irq,
269 .ack_irq = omap2_mbox_ack_irq,
270 .is_irq = omap2_mbox_is_irq,
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700271 .save_ctx = omap2_mbox_save_ctx,
272 .restore_ctx = omap2_mbox_restore_ctx,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800273};
274
275/*
276 * MAILBOX 0: ARM -> DSP,
277 * MAILBOX 1: ARM <- DSP.
278 * MAILBOX 2: ARM -> IVA,
279 * MAILBOX 3: ARM <- IVA.
280 */
281
282/* FIXME: the following structs should be filled automatically by the user id */
Felipe Contreras07d65d82010-06-11 15:51:38 +0000283
Omar Ramirez Lunaff0fba02010-10-22 20:10:58 -0500284#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP2)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800285/* DSP */
286static struct omap_mbox2_priv omap2_mbox_dsp_priv = {
287 .tx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700288 .msg = MAILBOX_MESSAGE(0),
289 .fifo_stat = MAILBOX_FIFOSTATUS(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800290 },
291 .rx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700292 .msg = MAILBOX_MESSAGE(1),
293 .msg_stat = MAILBOX_MSGSTATUS(1),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800294 },
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700295 .irqenable = MAILBOX_IRQENABLE(0),
296 .irqstatus = MAILBOX_IRQSTATUS(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800297 .notfull_bit = MAILBOX_IRQ_NOTFULL(0),
298 .newmsg_bit = MAILBOX_IRQ_NEWMSG(1),
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800299 .irqdisable = MAILBOX_IRQENABLE(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800300};
301
Felipe Contreras07d65d82010-06-11 15:51:38 +0000302struct omap_mbox mbox_dsp_info = {
303 .name = "dsp",
304 .ops = &omap2_mbox_ops,
305 .priv = &omap2_mbox_dsp_priv,
306};
Felipe Contreras14476bd2010-06-11 15:51:47 +0000307#endif
Felipe Contreras07d65d82010-06-11 15:51:38 +0000308
Omar Ramirez Lunaff0fba02010-10-22 20:10:58 -0500309#if defined(CONFIG_ARCH_OMAP3)
Felipe Contreras898ee752010-06-11 15:51:45 +0000310struct omap_mbox *omap3_mboxes[] = { &mbox_dsp_info, NULL };
Felipe Contreras14476bd2010-06-11 15:51:47 +0000311#endif
Felipe Contreras898ee752010-06-11 15:51:45 +0000312
Felipe Contreras07d65d82010-06-11 15:51:38 +0000313#if defined(CONFIG_ARCH_OMAP2420)
Felipe Contreras07d65d82010-06-11 15:51:38 +0000314/* IVA */
315static struct omap_mbox2_priv omap2_mbox_iva_priv = {
316 .tx_fifo = {
317 .msg = MAILBOX_MESSAGE(2),
318 .fifo_stat = MAILBOX_FIFOSTATUS(2),
319 },
320 .rx_fifo = {
321 .msg = MAILBOX_MESSAGE(3),
322 .msg_stat = MAILBOX_MSGSTATUS(3),
323 },
324 .irqenable = MAILBOX_IRQENABLE(3),
325 .irqstatus = MAILBOX_IRQSTATUS(3),
326 .notfull_bit = MAILBOX_IRQ_NOTFULL(2),
327 .newmsg_bit = MAILBOX_IRQ_NEWMSG(3),
328 .irqdisable = MAILBOX_IRQENABLE(3),
329};
330
331static struct omap_mbox mbox_iva_info = {
332 .name = "iva",
333 .ops = &omap2_mbox_ops,
334 .priv = &omap2_mbox_iva_priv,
335};
Felipe Contreras898ee752010-06-11 15:51:45 +0000336
337struct omap_mbox *omap2_mboxes[] = { &mbox_iva_info, &mbox_dsp_info, NULL };
Felipe Contreras07d65d82010-06-11 15:51:38 +0000338#endif
339
Felipe Contreras14476bd2010-06-11 15:51:47 +0000340#if defined(CONFIG_ARCH_OMAP4)
Felipe Contreras07d65d82010-06-11 15:51:38 +0000341/* OMAP4 */
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800342static struct omap_mbox2_priv omap2_mbox_1_priv = {
343 .tx_fifo = {
344 .msg = MAILBOX_MESSAGE(0),
345 .fifo_stat = MAILBOX_FIFOSTATUS(0),
346 },
347 .rx_fifo = {
348 .msg = MAILBOX_MESSAGE(1),
349 .msg_stat = MAILBOX_MSGSTATUS(1),
350 },
351 .irqenable = OMAP4_MAILBOX_IRQENABLE(0),
352 .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0),
353 .notfull_bit = MAILBOX_IRQ_NOTFULL(0),
354 .newmsg_bit = MAILBOX_IRQ_NEWMSG(1),
355 .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0),
356};
357
358struct omap_mbox mbox_1_info = {
359 .name = "mailbox-1",
360 .ops = &omap2_mbox_ops,
361 .priv = &omap2_mbox_1_priv,
362};
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800363
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800364static struct omap_mbox2_priv omap2_mbox_2_priv = {
365 .tx_fifo = {
366 .msg = MAILBOX_MESSAGE(3),
367 .fifo_stat = MAILBOX_FIFOSTATUS(3),
368 },
369 .rx_fifo = {
370 .msg = MAILBOX_MESSAGE(2),
371 .msg_stat = MAILBOX_MSGSTATUS(2),
372 },
373 .irqenable = OMAP4_MAILBOX_IRQENABLE(0),
374 .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0),
375 .notfull_bit = MAILBOX_IRQ_NOTFULL(3),
376 .newmsg_bit = MAILBOX_IRQ_NEWMSG(2),
377 .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0),
378};
379
380struct omap_mbox mbox_2_info = {
381 .name = "mailbox-2",
382 .ops = &omap2_mbox_ops,
383 .priv = &omap2_mbox_2_priv,
384};
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800385
Felipe Contreras898ee752010-06-11 15:51:45 +0000386struct omap_mbox *omap4_mboxes[] = { &mbox_1_info, &mbox_2_info, NULL };
Felipe Contreras14476bd2010-06-11 15:51:47 +0000387#endif
Felipe Contreras898ee752010-06-11 15:51:45 +0000388
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700389static int __devinit omap2_mbox_probe(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800390{
Felipe Contreras898ee752010-06-11 15:51:45 +0000391 struct resource *mem;
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700392 int ret;
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000393 struct omap_mbox **list;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800394
Felipe Contreras14476bd2010-06-11 15:51:47 +0000395 if (false)
396 ;
Omar Ramirez Lunaff0fba02010-10-22 20:10:58 -0500397#if defined(CONFIG_ARCH_OMAP3)
398 else if (cpu_is_omap34xx()) {
Felipe Contreras898ee752010-06-11 15:51:45 +0000399 list = omap3_mboxes;
400
401 list[0]->irq = platform_get_irq_byname(pdev, "dsp");
402 }
Felipe Contreras14476bd2010-06-11 15:51:47 +0000403#endif
Omar Ramirez Lunaff0fba02010-10-22 20:10:58 -0500404#if defined(CONFIG_ARCH_OMAP2)
405 else if (cpu_is_omap2430()) {
406 list = omap2_mboxes;
407
408 list[0]->irq = platform_get_irq_byname(pdev, "dsp");
409 } else if (cpu_is_omap2420()) {
Felipe Contreras898ee752010-06-11 15:51:45 +0000410 list = omap2_mboxes;
411
412 list[0]->irq = platform_get_irq_byname(pdev, "dsp");
413 list[1]->irq = platform_get_irq_byname(pdev, "iva");
414 }
415#endif
Felipe Contreras14476bd2010-06-11 15:51:47 +0000416#if defined(CONFIG_ARCH_OMAP4)
Felipe Contreras898ee752010-06-11 15:51:45 +0000417 else if (cpu_is_omap44xx()) {
418 list = omap4_mboxes;
419
420 list[0]->irq = list[1]->irq =
421 platform_get_irq_byname(pdev, "mbox");
422 }
Felipe Contreras14476bd2010-06-11 15:51:47 +0000423#endif
Felipe Contreras898ee752010-06-11 15:51:45 +0000424 else {
425 pr_err("%s: platform not supported\n", __func__);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800426 return -ENODEV;
427 }
Felipe Contreras898ee752010-06-11 15:51:45 +0000428
429 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
430 mbox_base = ioremap(mem->start, resource_size(mem));
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700431 if (!mbox_base)
432 return -ENOMEM;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800433
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000434 ret = omap_mbox_register(&pdev->dev, list);
435 if (ret) {
436 iounmap(mbox_base);
437 return ret;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800438 }
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800439
Omar Ramirez Luna5d783732010-12-01 14:15:08 -0600440 return 0;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800441}
442
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700443static int __devexit omap2_mbox_remove(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800444{
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000445 omap_mbox_unregister();
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700446 iounmap(mbox_base);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800447 return 0;
448}
449
450static struct platform_driver omap2_mbox_driver = {
451 .probe = omap2_mbox_probe,
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700452 .remove = __devexit_p(omap2_mbox_remove),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800453 .driver = {
Felipe Contrerasd7427092010-06-11 15:51:48 +0000454 .name = "omap-mailbox",
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800455 },
456};
457
458static int __init omap2_mbox_init(void)
459{
460 return platform_driver_register(&omap2_mbox_driver);
461}
462
463static void __exit omap2_mbox_exit(void)
464{
465 platform_driver_unregister(&omap2_mbox_driver);
466}
467
468module_init(omap2_mbox_init);
469module_exit(omap2_mbox_exit);
470
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700471MODULE_LICENSE("GPL v2");
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800472MODULE_DESCRIPTION("omap mailbox: omap2/3/4 architecture specific functions");
Ohad Ben-Cohenf3753252010-05-05 15:33:07 +0000473MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
474MODULE_AUTHOR("Paul Mundt");
Felipe Contrerasd7427092010-06-11 15:51:48 +0000475MODULE_ALIAS("platform:omap2-mailbox");