blob: b01aae69010f76be72fb7f58f60235d9b3b2294f [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
Tony Lindgrena1bcc1d2011-11-07 12:27:10 -080013#include <linux/module.h>
Hiroshi DOYU340a6142006-12-07 15:43:59 -080014#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>
Omar Ramirez Luna82d2a5d2011-02-24 12:51:33 -080018#include <linux/pm_runtime.h>
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070019
Tony Lindgrence491cf2009-10-20 09:40:47 -070020#include <plat/mailbox.h>
Hiroshi DOYU340a6142006-12-07 15:43:59 -080021
Tony Lindgrendbc04162012-08-31 10:59:07 -070022#include "soc.h"
23
Hiroshi DOYU733ecc52009-03-23 18:07:23 -070024#define MAILBOX_REVISION 0x000
Hiroshi DOYU733ecc52009-03-23 18:07:23 -070025#define MAILBOX_MESSAGE(m) (0x040 + 4 * (m))
26#define MAILBOX_FIFOSTATUS(m) (0x080 + 4 * (m))
27#define MAILBOX_MSGSTATUS(m) (0x0c0 + 4 * (m))
28#define MAILBOX_IRQSTATUS(u) (0x100 + 8 * (u))
29#define MAILBOX_IRQENABLE(u) (0x104 + 8 * (u))
30
Tony Lindgren256a4bd2012-05-08 16:31:13 -070031#define OMAP4_MAILBOX_IRQSTATUS(u) (0x104 + 0x10 * (u))
32#define OMAP4_MAILBOX_IRQENABLE(u) (0x108 + 0x10 * (u))
33#define OMAP4_MAILBOX_IRQENABLE_CLR(u) (0x10c + 0x10 * (u))
C A Subramaniam5f00ec62009-11-22 10:11:22 -080034
35#define MAILBOX_IRQ_NEWMSG(m) (1 << (2 * (m)))
36#define MAILBOX_IRQ_NOTFULL(m) (1 << (2 * (m) + 1))
Hiroshi DOYU340a6142006-12-07 15:43:59 -080037
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070038#define MBOX_REG_SIZE 0x120
C A Subramaniam5f00ec62009-11-22 10:11:22 -080039
40#define OMAP4_MBOX_REG_SIZE 0x130
41
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070042#define MBOX_NR_REGS (MBOX_REG_SIZE / sizeof(u32))
C A Subramaniam5f00ec62009-11-22 10:11:22 -080043#define OMAP4_MBOX_NR_REGS (OMAP4_MBOX_REG_SIZE / sizeof(u32))
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070044
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070045static void __iomem *mbox_base;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080046
Hiroshi DOYU340a6142006-12-07 15:43:59 -080047struct omap_mbox2_fifo {
48 unsigned long msg;
49 unsigned long fifo_stat;
50 unsigned long msg_stat;
51};
52
53struct omap_mbox2_priv {
54 struct omap_mbox2_fifo tx_fifo;
55 struct omap_mbox2_fifo rx_fifo;
56 unsigned long irqenable;
57 unsigned long irqstatus;
58 u32 newmsg_bit;
59 u32 notfull_bit;
C A Subramaniam5f00ec62009-11-22 10:11:22 -080060 u32 ctx[OMAP4_MBOX_NR_REGS];
61 unsigned long irqdisable;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080062};
63
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070064static inline unsigned int mbox_read_reg(size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080065{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070066 return __raw_readl(mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080067}
68
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070069static inline void mbox_write_reg(u32 val, size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080070{
Hiroshi DOYU6c20a682009-03-23 18:07:23 -070071 __raw_writel(val, mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080072}
73
74/* Mailbox H/W preparations */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +030075static int omap2_mbox_startup(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080076{
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070077 u32 l;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080078
Omar Ramirez Luna82d2a5d2011-02-24 12:51:33 -080079 pm_runtime_enable(mbox->dev->parent);
80 pm_runtime_get_sync(mbox->dev->parent);
Hiroshi DOYU1ffe6272009-09-24 16:23:09 -070081
Hiroshi DOYU94fc58c2009-03-23 18:07:24 -070082 l = mbox_read_reg(MAILBOX_REVISION);
Felipe Contreras909f9dc2010-06-11 15:51:37 +000083 pr_debug("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));
Hiroshi DOYU94fc58c2009-03-23 18:07:24 -070084
Hiroshi DOYU340a6142006-12-07 15:43:59 -080085 return 0;
86}
87
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +030088static void omap2_mbox_shutdown(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080089{
Omar Ramirez Luna82d2a5d2011-02-24 12:51:33 -080090 pm_runtime_put_sync(mbox->dev->parent);
91 pm_runtime_disable(mbox->dev->parent);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080092}
93
94/* Mailbox FIFO handle functions */
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +030095static mbox_msg_t omap2_mbox_fifo_read(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080096{
97 struct omap_mbox2_fifo *fifo =
98 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
99 return (mbox_msg_t) mbox_read_reg(fifo->msg);
100}
101
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300102static void omap2_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800103{
104 struct omap_mbox2_fifo *fifo =
105 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
106 mbox_write_reg(msg, fifo->msg);
107}
108
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300109static int omap2_mbox_fifo_empty(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800110{
111 struct omap_mbox2_fifo *fifo =
112 &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
113 return (mbox_read_reg(fifo->msg_stat) == 0);
114}
115
Hiroshi DOYUbfbdcf82007-07-30 14:04:04 +0300116static int omap2_mbox_fifo_full(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800117{
118 struct omap_mbox2_fifo *fifo =
119 &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800120 return mbox_read_reg(fifo->fifo_stat);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800121}
122
123/* Mailbox IRQ handle functions */
Suman Annaf91ca052013-06-07 16:27:45 -0500124static void omap2_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800125{
matt mooneyb45b5012010-09-27 19:04:32 -0700126 struct omap_mbox2_priv *p = mbox->priv;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800127 u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
128
129 l = mbox_read_reg(p->irqenable);
130 l |= bit;
131 mbox_write_reg(l, p->irqenable);
132}
133
Suman Annaf91ca052013-06-07 16:27:45 -0500134static void omap2_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800135{
matt mooneyb45b5012010-09-27 19:04:32 -0700136 struct omap_mbox2_priv *p = mbox->priv;
Hari Kanigeri525a1132011-03-02 22:14:18 +0000137 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
138
139 if (!cpu_is_omap44xx())
140 bit = mbox_read_reg(p->irqdisable) & ~bit;
141
142 mbox_write_reg(bit, p->irqdisable);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800143}
144
Suman Annaf91ca052013-06-07 16:27:45 -0500145static void omap2_mbox_ack_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800146{
matt mooneyb45b5012010-09-27 19:04:32 -0700147 struct omap_mbox2_priv *p = mbox->priv;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800148 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
149
150 mbox_write_reg(bit, p->irqstatus);
Hiroshi DOYU88288802009-09-24 16:23:10 -0700151
152 /* Flush posted write for irq status to avoid spurious interrupts */
153 mbox_read_reg(p->irqstatus);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800154}
155
Suman Annaf91ca052013-06-07 16:27:45 -0500156static int omap2_mbox_is_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800157{
matt mooneyb45b5012010-09-27 19:04:32 -0700158 struct omap_mbox2_priv *p = mbox->priv;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800159 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit;
160 u32 enable = mbox_read_reg(p->irqenable);
161 u32 status = mbox_read_reg(p->irqstatus);
162
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800163 return (int)(enable & status & bit);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800164}
165
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700166static void omap2_mbox_save_ctx(struct omap_mbox *mbox)
167{
168 int i;
169 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800170 int nr_regs;
171 if (cpu_is_omap44xx())
172 nr_regs = OMAP4_MBOX_NR_REGS;
173 else
174 nr_regs = MBOX_NR_REGS;
175 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700176 p->ctx[i] = mbox_read_reg(i * sizeof(u32));
177
178 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
179 i, p->ctx[i]);
180 }
181}
182
183static void omap2_mbox_restore_ctx(struct omap_mbox *mbox)
184{
185 int i;
186 struct omap_mbox2_priv *p = mbox->priv;
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800187 int nr_regs;
188 if (cpu_is_omap44xx())
189 nr_regs = OMAP4_MBOX_NR_REGS;
190 else
191 nr_regs = MBOX_NR_REGS;
192 for (i = 0; i < nr_regs; i++) {
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700193 mbox_write_reg(p->ctx[i], i * sizeof(u32));
194
195 dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
196 i, p->ctx[i]);
197 }
198}
199
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800200static struct omap_mbox_ops omap2_mbox_ops = {
201 .type = OMAP_MBOX_TYPE2,
202 .startup = omap2_mbox_startup,
203 .shutdown = omap2_mbox_shutdown,
204 .fifo_read = omap2_mbox_fifo_read,
205 .fifo_write = omap2_mbox_fifo_write,
206 .fifo_empty = omap2_mbox_fifo_empty,
207 .fifo_full = omap2_mbox_fifo_full,
208 .enable_irq = omap2_mbox_enable_irq,
209 .disable_irq = omap2_mbox_disable_irq,
210 .ack_irq = omap2_mbox_ack_irq,
211 .is_irq = omap2_mbox_is_irq,
Hiroshi DOYUc75ee752009-03-23 18:07:26 -0700212 .save_ctx = omap2_mbox_save_ctx,
213 .restore_ctx = omap2_mbox_restore_ctx,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800214};
215
216/*
217 * MAILBOX 0: ARM -> DSP,
218 * MAILBOX 1: ARM <- DSP.
219 * MAILBOX 2: ARM -> IVA,
220 * MAILBOX 3: ARM <- IVA.
221 */
222
223/* FIXME: the following structs should be filled automatically by the user id */
Felipe Contreras07d65d82010-06-11 15:51:38 +0000224
Omar Ramirez Lunaff0fba02010-10-22 20:10:58 -0500225#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP2)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800226/* DSP */
227static struct omap_mbox2_priv omap2_mbox_dsp_priv = {
228 .tx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700229 .msg = MAILBOX_MESSAGE(0),
230 .fifo_stat = MAILBOX_FIFOSTATUS(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800231 },
232 .rx_fifo = {
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700233 .msg = MAILBOX_MESSAGE(1),
234 .msg_stat = MAILBOX_MSGSTATUS(1),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800235 },
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700236 .irqenable = MAILBOX_IRQENABLE(0),
237 .irqstatus = MAILBOX_IRQSTATUS(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800238 .notfull_bit = MAILBOX_IRQ_NOTFULL(0),
239 .newmsg_bit = MAILBOX_IRQ_NEWMSG(1),
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800240 .irqdisable = MAILBOX_IRQENABLE(0),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800241};
242
Felipe Contreras07d65d82010-06-11 15:51:38 +0000243struct omap_mbox mbox_dsp_info = {
244 .name = "dsp",
245 .ops = &omap2_mbox_ops,
246 .priv = &omap2_mbox_dsp_priv,
247};
Felipe Contreras14476bd2010-06-11 15:51:47 +0000248#endif
Felipe Contreras07d65d82010-06-11 15:51:38 +0000249
Omar Ramirez Lunaff0fba02010-10-22 20:10:58 -0500250#if defined(CONFIG_ARCH_OMAP3)
Felipe Contreras898ee752010-06-11 15:51:45 +0000251struct omap_mbox *omap3_mboxes[] = { &mbox_dsp_info, NULL };
Felipe Contreras14476bd2010-06-11 15:51:47 +0000252#endif
Felipe Contreras898ee752010-06-11 15:51:45 +0000253
Tony Lindgren59b479e2011-01-27 16:39:40 -0800254#if defined(CONFIG_SOC_OMAP2420)
Felipe Contreras07d65d82010-06-11 15:51:38 +0000255/* IVA */
256static struct omap_mbox2_priv omap2_mbox_iva_priv = {
257 .tx_fifo = {
258 .msg = MAILBOX_MESSAGE(2),
259 .fifo_stat = MAILBOX_FIFOSTATUS(2),
260 },
261 .rx_fifo = {
262 .msg = MAILBOX_MESSAGE(3),
263 .msg_stat = MAILBOX_MSGSTATUS(3),
264 },
265 .irqenable = MAILBOX_IRQENABLE(3),
266 .irqstatus = MAILBOX_IRQSTATUS(3),
267 .notfull_bit = MAILBOX_IRQ_NOTFULL(2),
268 .newmsg_bit = MAILBOX_IRQ_NEWMSG(3),
269 .irqdisable = MAILBOX_IRQENABLE(3),
270};
271
272static struct omap_mbox mbox_iva_info = {
273 .name = "iva",
274 .ops = &omap2_mbox_ops,
275 .priv = &omap2_mbox_iva_priv,
276};
Ohad Ben-Cohen655850e2012-02-23 10:53:35 +0200277#endif
Felipe Contreras898ee752010-06-11 15:51:45 +0000278
Ohad Ben-Cohen655850e2012-02-23 10:53:35 +0200279#ifdef CONFIG_ARCH_OMAP2
280struct omap_mbox *omap2_mboxes[] = {
281 &mbox_dsp_info,
282#ifdef CONFIG_SOC_OMAP2420
283 &mbox_iva_info,
284#endif
285 NULL
286};
Felipe Contreras07d65d82010-06-11 15:51:38 +0000287#endif
288
Felipe Contreras14476bd2010-06-11 15:51:47 +0000289#if defined(CONFIG_ARCH_OMAP4)
Felipe Contreras07d65d82010-06-11 15:51:38 +0000290/* OMAP4 */
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800291static struct omap_mbox2_priv omap2_mbox_1_priv = {
292 .tx_fifo = {
293 .msg = MAILBOX_MESSAGE(0),
294 .fifo_stat = MAILBOX_FIFOSTATUS(0),
295 },
296 .rx_fifo = {
297 .msg = MAILBOX_MESSAGE(1),
298 .msg_stat = MAILBOX_MSGSTATUS(1),
299 },
300 .irqenable = OMAP4_MAILBOX_IRQENABLE(0),
301 .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0),
302 .notfull_bit = MAILBOX_IRQ_NOTFULL(0),
303 .newmsg_bit = MAILBOX_IRQ_NEWMSG(1),
304 .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0),
305};
306
307struct omap_mbox mbox_1_info = {
308 .name = "mailbox-1",
309 .ops = &omap2_mbox_ops,
310 .priv = &omap2_mbox_1_priv,
311};
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800312
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800313static struct omap_mbox2_priv omap2_mbox_2_priv = {
314 .tx_fifo = {
315 .msg = MAILBOX_MESSAGE(3),
316 .fifo_stat = MAILBOX_FIFOSTATUS(3),
317 },
318 .rx_fifo = {
319 .msg = MAILBOX_MESSAGE(2),
320 .msg_stat = MAILBOX_MSGSTATUS(2),
321 },
322 .irqenable = OMAP4_MAILBOX_IRQENABLE(0),
323 .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0),
324 .notfull_bit = MAILBOX_IRQ_NOTFULL(3),
325 .newmsg_bit = MAILBOX_IRQ_NEWMSG(2),
326 .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0),
327};
328
329struct omap_mbox mbox_2_info = {
330 .name = "mailbox-2",
331 .ops = &omap2_mbox_ops,
332 .priv = &omap2_mbox_2_priv,
333};
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800334
Felipe Contreras898ee752010-06-11 15:51:45 +0000335struct omap_mbox *omap4_mboxes[] = { &mbox_1_info, &mbox_2_info, NULL };
Felipe Contreras14476bd2010-06-11 15:51:47 +0000336#endif
Felipe Contreras898ee752010-06-11 15:51:45 +0000337
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800338static int omap2_mbox_probe(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800339{
Felipe Contreras898ee752010-06-11 15:51:45 +0000340 struct resource *mem;
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700341 int ret;
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000342 struct omap_mbox **list;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800343
Felipe Contreras14476bd2010-06-11 15:51:47 +0000344 if (false)
345 ;
Omar Ramirez Lunaff0fba02010-10-22 20:10:58 -0500346#if defined(CONFIG_ARCH_OMAP3)
347 else if (cpu_is_omap34xx()) {
Felipe Contreras898ee752010-06-11 15:51:45 +0000348 list = omap3_mboxes;
349
Felipe Contreras69dbf852011-02-24 12:51:33 -0800350 list[0]->irq = platform_get_irq(pdev, 0);
Felipe Contreras898ee752010-06-11 15:51:45 +0000351 }
Felipe Contreras14476bd2010-06-11 15:51:47 +0000352#endif
Omar Ramirez Lunaff0fba02010-10-22 20:10:58 -0500353#if defined(CONFIG_ARCH_OMAP2)
354 else if (cpu_is_omap2430()) {
355 list = omap2_mboxes;
356
Felipe Contreras69dbf852011-02-24 12:51:33 -0800357 list[0]->irq = platform_get_irq(pdev, 0);
Omar Ramirez Lunaff0fba02010-10-22 20:10:58 -0500358 } else if (cpu_is_omap2420()) {
Felipe Contreras898ee752010-06-11 15:51:45 +0000359 list = omap2_mboxes;
360
361 list[0]->irq = platform_get_irq_byname(pdev, "dsp");
362 list[1]->irq = platform_get_irq_byname(pdev, "iva");
363 }
364#endif
Felipe Contreras14476bd2010-06-11 15:51:47 +0000365#if defined(CONFIG_ARCH_OMAP4)
Felipe Contreras898ee752010-06-11 15:51:45 +0000366 else if (cpu_is_omap44xx()) {
367 list = omap4_mboxes;
368
Felipe Contreras69dbf852011-02-24 12:51:33 -0800369 list[0]->irq = list[1]->irq = platform_get_irq(pdev, 0);
Felipe Contreras898ee752010-06-11 15:51:45 +0000370 }
Felipe Contreras14476bd2010-06-11 15:51:47 +0000371#endif
Felipe Contreras898ee752010-06-11 15:51:45 +0000372 else {
373 pr_err("%s: platform not supported\n", __func__);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800374 return -ENODEV;
375 }
Felipe Contreras898ee752010-06-11 15:51:45 +0000376
377 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Suman Annaa41677c2013-02-01 20:24:51 -0600378 if (!mem)
379 return -ENOENT;
380
Felipe Contreras898ee752010-06-11 15:51:45 +0000381 mbox_base = ioremap(mem->start, resource_size(mem));
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700382 if (!mbox_base)
383 return -ENOMEM;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800384
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000385 ret = omap_mbox_register(&pdev->dev, list);
386 if (ret) {
387 iounmap(mbox_base);
388 return ret;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800389 }
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800390
Omar Ramirez Luna5d783732010-12-01 14:15:08 -0600391 return 0;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800392}
393
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800394static int omap2_mbox_remove(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800395{
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000396 omap_mbox_unregister();
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700397 iounmap(mbox_base);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800398 return 0;
399}
400
401static struct platform_driver omap2_mbox_driver = {
402 .probe = omap2_mbox_probe,
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800403 .remove = omap2_mbox_remove,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800404 .driver = {
Felipe Contrerasd7427092010-06-11 15:51:48 +0000405 .name = "omap-mailbox",
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800406 },
407};
408
409static int __init omap2_mbox_init(void)
410{
411 return platform_driver_register(&omap2_mbox_driver);
412}
413
414static void __exit omap2_mbox_exit(void)
415{
416 platform_driver_unregister(&omap2_mbox_driver);
417}
418
Ohad Ben-Cohen134d12f2012-03-04 12:01:11 +0200419module_init(omap2_mbox_init);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800420module_exit(omap2_mbox_exit);
421
Hiroshi DOYU733ecc52009-03-23 18:07:23 -0700422MODULE_LICENSE("GPL v2");
C A Subramaniam5f00ec62009-11-22 10:11:22 -0800423MODULE_DESCRIPTION("omap mailbox: omap2/3/4 architecture specific functions");
Ohad Ben-Cohenf3753252010-05-05 15:33:07 +0000424MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
425MODULE_AUTHOR("Paul Mundt");
Felipe Contrerasd7427092010-06-11 15:51:48 +0000426MODULE_ALIAS("platform:omap2-mailbox");