blob: e5abc8e42f527e780edea1326b45e4dae3431a1b [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
Felipe Contreras898ee752010-06-11 15:51:45 +000059static struct omap_mbox **list;
60
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080061struct omap_mbox2_fifo {
62 unsigned long msg;
63 unsigned long fifo_stat;
64 unsigned long msg_stat;
65};
66
67struct omap_mbox2_priv {
68 struct omap_mbox2_fifo tx_fifo;
69 struct omap_mbox2_fifo rx_fifo;
70 unsigned long irqenable;
71 unsigned long irqstatus;
72 u32 newmsg_bit;
73 u32 notfull_bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -080074 u32 ctx[OMAP4_MBOX_NR_REGS];
75 unsigned long irqdisable;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080076};
77
78static struct clk *mbox_ick_handle;
79
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +030080static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
81 omap_mbox_type_t irq);
82
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070083static inline unsigned int mbox_read_reg(size_t ofs)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080084{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070085 return __raw_readl(mbox_base + ofs);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080086}
87
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070088static inline void mbox_write_reg(u32 val, size_t ofs)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080089{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070090 __raw_writel(val, mbox_base + ofs);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080091}
92
93/* Mailbox H/W preparations */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +030094static int omap2_mbox_startup(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080095{
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070096 u32 l;
97 unsigned long timeout;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080098
99 mbox_ick_handle = clk_get(NULL, "mailboxes_ick");
100 if (IS_ERR(mbox_ick_handle)) {
Felipe Balbi0cd7e1c2010-02-15 10:03:33 -0800101 printk(KERN_ERR "Could not get mailboxes_ick: %ld\n",
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800102 PTR_ERR(mbox_ick_handle));
103 return PTR_ERR(mbox_ick_handle);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800104 }
105 clk_enable(mbox_ick_handle);
106
Suman Annaa6a60222010-01-26 16:55:29 -0600107 if (cpu_is_omap44xx()) {
108 mbox_write_reg(OMAP4_SOFTRESET, MAILBOX_SYSCONFIG);
109 timeout = jiffies + msecs_to_jiffies(20);
110 do {
111 l = mbox_read_reg(MAILBOX_SYSCONFIG);
112 if (!(l & OMAP4_SOFTRESET))
113 break;
114 } while (!time_after(jiffies, timeout));
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -0700115
Suman Annaa6a60222010-01-26 16:55:29 -0600116 if (l & OMAP4_SOFTRESET) {
117 pr_err("Can't take mailbox out of reset\n");
118 return -ENODEV;
119 }
120 } else {
121 mbox_write_reg(SOFTRESET, MAILBOX_SYSCONFIG);
122 timeout = jiffies + msecs_to_jiffies(20);
123 do {
124 l = mbox_read_reg(MAILBOX_SYSSTATUS);
125 if (l & RESETDONE)
126 break;
127 } while (!time_after(jiffies, timeout));
128
129 if (!(l & RESETDONE)) {
130 pr_err("Can't take mailbox out of reset\n");
131 return -ENODEV;
132 }
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -0700133 }
134
Hiroshi DOYU94fc58c2009-03-23 18:07:24 -0700135 l = mbox_read_reg(MAILBOX_REVISION);
Felipe Contreras909f9dc2010-06-11 15:51:37 +0000136 pr_debug("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));
Hiroshi DOYU94fc58c2009-03-23 18:07:24 -0700137
Suman Anna4499ce42010-02-05 17:20:26 -0600138 if (cpu_is_omap44xx())
139 l = OMAP4_SMARTIDLE;
140 else
141 l = SMARTIDLE | AUTOIDLE;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800142 mbox_write_reg(l, MAILBOX_SYSCONFIG);
143
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300144 omap2_mbox_enable_irq(mbox, IRQ_RX);
145
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800146 return 0;
147}
148
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300149static void omap2_mbox_shutdown(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800150{
151 clk_disable(mbox_ick_handle);
152 clk_put(mbox_ick_handle);
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800153 mbox_ick_handle = NULL;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800154}
155
156/* Mailbox FIFO handle functions */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300157static mbox_msg_t omap2_mbox_fifo_read(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800158{
159 struct omap_mbox2_fifo *fifo =
160 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
161 return (mbox_msg_t) mbox_read_reg(fifo->msg);
162}
163
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300164static void omap2_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800165{
166 struct omap_mbox2_fifo *fifo =
167 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
168 mbox_write_reg(msg, fifo->msg);
169}
170
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300171static int omap2_mbox_fifo_empty(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800172{
173 struct omap_mbox2_fifo *fifo =
174 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
175 return (mbox_read_reg(fifo->msg_stat) == 0);
176}
177
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300178static int omap2_mbox_fifo_full(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800179{
180 struct omap_mbox2_fifo *fifo =
181 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800182 return mbox_read_reg(fifo->fifo_stat);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800183}
184
185/* Mailbox IRQ handle functions */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300186static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800187 omap_mbox_type_t irq)
188{
189 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
190 u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
191
192 l = mbox_read_reg(p->irqenable);
193 l |= bit;
194 mbox_write_reg(l, p->irqenable);
195}
196
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300197static void omap2_mbox_disable_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800198 omap_mbox_type_t irq)
199{
200 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
201 u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800202 l = mbox_read_reg(p->irqdisable);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800203 l &= ~bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800204 mbox_write_reg(l, p->irqdisable);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800205}
206
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300207static void omap2_mbox_ack_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800208 omap_mbox_type_t irq)
209{
210 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
211 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
212
213 mbox_write_reg(bit, p->irqstatus);
Hiroshi DOYU88288802009-09-24 16:23:10 -0700214
215 /* Flush posted write for irq status to avoid spurious interrupts */
216 mbox_read_reg(p->irqstatus);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800217}
218
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300219static int omap2_mbox_is_irq(struct omap_mbox *mbox,
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800220 omap_mbox_type_t irq)
221{
222 struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv;
223 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
224 u32 enable = mbox_read_reg(p->irqenable);
225 u32 status = mbox_read_reg(p->irqstatus);
226
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800227 return (int)(enable & status & bit);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800228}
229
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700230static void omap2_mbox_save_ctx(struct omap_mbox *mbox)
231{
232 int i;
233 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800234 int nr_regs;
235 if (cpu_is_omap44xx())
236 nr_regs = OMAP4_MBOX_NR_REGS;
237 else
238 nr_regs = MBOX_NR_REGS;
239 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700240 p->ctx[i] = mbox_read_reg(i * sizeof(u32));
241
242 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
243 i, p->ctx[i]);
244 }
245}
246
247static void omap2_mbox_restore_ctx(struct omap_mbox *mbox)
248{
249 int i;
250 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800251 int nr_regs;
252 if (cpu_is_omap44xx())
253 nr_regs = OMAP4_MBOX_NR_REGS;
254 else
255 nr_regs = MBOX_NR_REGS;
256 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700257 mbox_write_reg(p->ctx[i], i * sizeof(u32));
258
259 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
260 i, p->ctx[i]);
261 }
262}
263
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800264static struct omap_mbox_ops omap2_mbox_ops = {
265 .type = OMAP_MBOX_TYPE2,
266 .startup = omap2_mbox_startup,
267 .shutdown = omap2_mbox_shutdown,
268 .fifo_read = omap2_mbox_fifo_read,
269 .fifo_write = omap2_mbox_fifo_write,
270 .fifo_empty = omap2_mbox_fifo_empty,
271 .fifo_full = omap2_mbox_fifo_full,
272 .enable_irq = omap2_mbox_enable_irq,
273 .disable_irq = omap2_mbox_disable_irq,
274 .ack_irq = omap2_mbox_ack_irq,
275 .is_irq = omap2_mbox_is_irq,
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700276 .save_ctx = omap2_mbox_save_ctx,
277 .restore_ctx = omap2_mbox_restore_ctx,
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800278};
279
280/*
281 * MAILBOX 0: ARM -> DSP,
282 * MAILBOX 1: ARM <- DSP.
283 * MAILBOX 2: ARM -> IVA,
284 * MAILBOX 3: ARM <- IVA.
285 */
286
287/* FIXME: the following structs should be filled automatically by the user id */
Felipe Contreras07d65d82010-06-11 15:51:38 +0000288
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800289/* DSP */
290static struct omap_mbox2_priv omap2_mbox_dsp_priv = {
291 .tx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700292 .msg = MAILBOX_MESSAGE(0),
293 .fifo_stat = MAILBOX_FIFOSTATUS(0),
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800294 },
295 .rx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700296 .msg = MAILBOX_MESSAGE(1),
297 .msg_stat = MAILBOX_MSGSTATUS(1),
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800298 },
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700299 .irqenable = MAILBOX_IRQENABLE(0),
300 .irqstatus = MAILBOX_IRQSTATUS(0),
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800301 .notfull_bit = MAILBOX_IRQ_NOTFULL(0),
302 .newmsg_bit = MAILBOX_IRQ_NEWMSG(1),
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800303 .irqdisable = MAILBOX_IRQENABLE(0),
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800304};
305
Felipe Contreras07d65d82010-06-11 15:51:38 +0000306struct omap_mbox mbox_dsp_info = {
307 .name = "dsp",
308 .ops = &omap2_mbox_ops,
309 .priv = &omap2_mbox_dsp_priv,
310};
Felipe Contreras07d65d82010-06-11 15:51:38 +0000311
Felipe Contreras898ee752010-06-11 15:51:45 +0000312struct omap_mbox *omap3_mboxes[] = { &mbox_dsp_info, NULL };
313
Felipe Contreras07d65d82010-06-11 15:51:38 +0000314#if defined(CONFIG_ARCH_OMAP2420)
315
316/* IVA */
317static struct omap_mbox2_priv omap2_mbox_iva_priv = {
318 .tx_fifo = {
319 .msg = MAILBOX_MESSAGE(2),
320 .fifo_stat = MAILBOX_FIFOSTATUS(2),
321 },
322 .rx_fifo = {
323 .msg = MAILBOX_MESSAGE(3),
324 .msg_stat = MAILBOX_MSGSTATUS(3),
325 },
326 .irqenable = MAILBOX_IRQENABLE(3),
327 .irqstatus = MAILBOX_IRQSTATUS(3),
328 .notfull_bit = MAILBOX_IRQ_NOTFULL(2),
329 .newmsg_bit = MAILBOX_IRQ_NEWMSG(3),
330 .irqdisable = MAILBOX_IRQENABLE(3),
331};
332
333static struct omap_mbox mbox_iva_info = {
334 .name = "iva",
335 .ops = &omap2_mbox_ops,
336 .priv = &omap2_mbox_iva_priv,
337};
Felipe Contreras898ee752010-06-11 15:51:45 +0000338
339struct omap_mbox *omap2_mboxes[] = { &mbox_iva_info, &mbox_dsp_info, NULL };
Felipe Contreras07d65d82010-06-11 15:51:38 +0000340#endif
341
342/* 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 };
388
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700389static int __devinit omap2_mbox_probe(struct platform_device *pdev)
Hiroshi DOYU340a614a2006-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 Contreras898ee752010-06-11 15:51:45 +0000393 int i;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800394
Felipe Contreras898ee752010-06-11 15:51:45 +0000395 if (cpu_is_omap3430()) {
396 list = omap3_mboxes;
397
398 list[0]->irq = platform_get_irq_byname(pdev, "dsp");
399 }
400#if defined(CONFIG_ARCH_OMAP2420)
401 else if (cpu_is_omap2420()) {
402 list = omap2_mboxes;
403
404 list[0]->irq = platform_get_irq_byname(pdev, "dsp");
405 list[1]->irq = platform_get_irq_byname(pdev, "iva");
406 }
407#endif
408 else if (cpu_is_omap44xx()) {
409 list = omap4_mboxes;
410
411 list[0]->irq = list[1]->irq =
412 platform_get_irq_byname(pdev, "mbox");
413 }
414 else {
415 pr_err("%s: platform not supported\n", __func__);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800416 return -ENODEV;
417 }
Felipe Contreras898ee752010-06-11 15:51:45 +0000418
419 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
420 mbox_base = ioremap(mem->start, resource_size(mem));
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700421 if (!mbox_base)
422 return -ENOMEM;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800423
Felipe Contreras898ee752010-06-11 15:51:45 +0000424 for (i = 0; list[i]; i++) {
425 ret = omap_mbox_register(&pdev->dev, list[i]);
426 if (ret)
427 goto err_out;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800428 }
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700429 return 0;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800430
Felipe Contreras898ee752010-06-11 15:51:45 +0000431err_out:
432 while (i--)
433 omap_mbox_unregister(list[i]);
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700434 iounmap(mbox_base);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800435 return ret;
436}
437
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700438static int __devexit omap2_mbox_remove(struct platform_device *pdev)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800439{
Felipe Contreras898ee752010-06-11 15:51:45 +0000440 int i;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800441
Felipe Contreras898ee752010-06-11 15:51:45 +0000442 for (i = 0; list[i]; i++)
443 omap_mbox_unregister(list[i]);
444
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700445 iounmap(mbox_base);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800446 return 0;
447}
448
449static struct platform_driver omap2_mbox_driver = {
450 .probe = omap2_mbox_probe,
Hiroshi DOYUda8cfe02009-03-23 18:07:25 -0700451 .remove = __devexit_p(omap2_mbox_remove),
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800452 .driver = {
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800453 .name = DRV_NAME,
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800454 },
455};
456
457static int __init omap2_mbox_init(void)
458{
459 return platform_driver_register(&omap2_mbox_driver);
460}
461
462static void __exit omap2_mbox_exit(void)
463{
464 platform_driver_unregister(&omap2_mbox_driver);
465}
466
467module_init(omap2_mbox_init);
468module_exit(omap2_mbox_exit);
469
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700470MODULE_LICENSE("GPL v2");
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800471MODULE_DESCRIPTION("omap mailbox: omap2/3/4 architecture specific functions");
Ohad Ben-Cohenf3753252010-05-05 15:33:07 +0000472MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
473MODULE_AUTHOR("Paul Mundt");
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800474MODULE_ALIAS("platform:"DRV_NAME);