blob: 0318754e85046be5de54abe8bc784abd582596e4 [file] [log] [blame]
Hiroshi DOYU340a6142006-12-07 15:43:59 -08001/*
2 * Mailbox reservation modules for DSP
3 *
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -07004 * Copyright (C) 2006-2009 Nokia Corporation
Hiroshi DOYU340a6142006-12-07 15:43:59 -08005 * Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11
12#include <linux/kernel.h>
13#include <linux/resource.h>
14#include <linux/interrupt.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
20#define MAILBOX_ARM2DSP1 0x00
21#define MAILBOX_ARM2DSP1b 0x04
22#define MAILBOX_DSP2ARM1 0x08
23#define MAILBOX_DSP2ARM1b 0x0c
24#define MAILBOX_DSP2ARM2 0x10
25#define MAILBOX_DSP2ARM2b 0x14
26#define MAILBOX_ARM2DSP1_Flag 0x18
27#define MAILBOX_DSP2ARM1_Flag 0x1c
28#define MAILBOX_DSP2ARM2_Flag 0x20
29
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070030static void __iomem *mbox_base;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080031
Felipe Contreras898ee752010-06-11 15:51:45 +000032static struct omap_mbox **list;
33
Hiroshi DOYU340a6142006-12-07 15:43:59 -080034struct omap_mbox1_fifo {
35 unsigned long cmd;
36 unsigned long data;
37 unsigned long flag;
38};
39
40struct omap_mbox1_priv {
41 struct omap_mbox1_fifo tx_fifo;
42 struct omap_mbox1_fifo rx_fifo;
43};
44
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070045static inline int mbox_read_reg(size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080046{
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070047 return __raw_readw(mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080048}
49
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070050static inline void mbox_write_reg(u32 val, size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080051{
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070052 __raw_writew(val, mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080053}
54
55/* msg */
Tony Lindgrene27a93a2007-12-18 20:58:32 -080056static mbox_msg_t omap1_mbox_fifo_read(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080057{
58 struct omap_mbox1_fifo *fifo =
59 &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
60 mbox_msg_t msg;
61
62 msg = mbox_read_reg(fifo->data);
63 msg |= ((mbox_msg_t) mbox_read_reg(fifo->cmd)) << 16;
64
65 return msg;
66}
67
Tony Lindgrene27a93a2007-12-18 20:58:32 -080068static void
Hiroshi DOYU340a6142006-12-07 15:43:59 -080069omap1_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
70{
71 struct omap_mbox1_fifo *fifo =
72 &((struct omap_mbox1_priv *)mbox->priv)->tx_fifo;
73
74 mbox_write_reg(msg & 0xffff, fifo->data);
75 mbox_write_reg(msg >> 16, fifo->cmd);
76}
77
Tony Lindgrene27a93a2007-12-18 20:58:32 -080078static int omap1_mbox_fifo_empty(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080079{
80 return 0;
81}
82
Tony Lindgrene27a93a2007-12-18 20:58:32 -080083static int omap1_mbox_fifo_full(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080084{
85 struct omap_mbox1_fifo *fifo =
86 &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
87
Felipe Contreras909f9dc2010-06-11 15:51:37 +000088 return mbox_read_reg(fifo->flag);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080089}
90
91/* irq */
Tony Lindgrene27a93a2007-12-18 20:58:32 -080092static void
Hiroshi DOYU340a6142006-12-07 15:43:59 -080093omap1_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
94{
95 if (irq == IRQ_RX)
96 enable_irq(mbox->irq);
97}
98
Tony Lindgrene27a93a2007-12-18 20:58:32 -080099static void
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800100omap1_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
101{
102 if (irq == IRQ_RX)
103 disable_irq(mbox->irq);
104}
105
Tony Lindgrene27a93a2007-12-18 20:58:32 -0800106static int
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800107omap1_mbox_is_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
108{
109 if (irq == IRQ_TX)
110 return 0;
111 return 1;
112}
113
114static struct omap_mbox_ops omap1_mbox_ops = {
115 .type = OMAP_MBOX_TYPE1,
116 .fifo_read = omap1_mbox_fifo_read,
117 .fifo_write = omap1_mbox_fifo_write,
118 .fifo_empty = omap1_mbox_fifo_empty,
119 .fifo_full = omap1_mbox_fifo_full,
120 .enable_irq = omap1_mbox_enable_irq,
121 .disable_irq = omap1_mbox_disable_irq,
122 .is_irq = omap1_mbox_is_irq,
123};
124
125/* FIXME: the following struct should be created automatically by the user id */
126
127/* DSP */
128static struct omap_mbox1_priv omap1_mbox_dsp_priv = {
129 .tx_fifo = {
130 .cmd = MAILBOX_ARM2DSP1b,
131 .data = MAILBOX_ARM2DSP1,
132 .flag = MAILBOX_ARM2DSP1_Flag,
133 },
134 .rx_fifo = {
135 .cmd = MAILBOX_DSP2ARM1b,
136 .data = MAILBOX_DSP2ARM1,
137 .flag = MAILBOX_DSP2ARM1_Flag,
138 },
139};
140
141struct omap_mbox mbox_dsp_info = {
142 .name = "dsp",
143 .ops = &omap1_mbox_ops,
144 .priv = &omap1_mbox_dsp_priv,
145};
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800146
Felipe Contreras898ee752010-06-11 15:51:45 +0000147struct omap_mbox *omap1_mboxes[] = { &mbox_dsp_info, NULL };
148
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700149static int __devinit omap1_mbox_probe(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800150{
Felipe Contreras898ee752010-06-11 15:51:45 +0000151 struct resource *mem;
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000152 int ret;
Felipe Contreras898ee752010-06-11 15:51:45 +0000153 int i;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800154
Felipe Contreras898ee752010-06-11 15:51:45 +0000155 list = omap1_mboxes;
Felipe Balbid7615852010-02-15 10:03:33 -0800156
Felipe Contreras898ee752010-06-11 15:51:45 +0000157 list[0]->irq = platform_get_irq_byname(pdev, "dsp");
158
159 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
160 mbox_base = ioremap(mem->start, resource_size(mem));
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000161 if (!mbox_base)
162 return -ENOMEM;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800163
Felipe Contreras898ee752010-06-11 15:51:45 +0000164 for (i = 0; list[i]; i++) {
165 ret = omap_mbox_register(&pdev->dev, list[i]);
166 if (ret)
167 goto err_out;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800168 }
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000169 return 0;
170
171err_out:
Felipe Contreras898ee752010-06-11 15:51:45 +0000172 while (i--)
173 omap_mbox_unregister(list[i]);
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000174 iounmap(mbox_base);
175 return ret;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800176}
177
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700178static int __devexit omap1_mbox_remove(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800179{
Felipe Contreras898ee752010-06-11 15:51:45 +0000180 int i;
181
182 for (i = 0; list[i]; i++)
183 omap_mbox_unregister(list[i]);
184
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000185 iounmap(mbox_base);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800186 return 0;
187}
188
189static struct platform_driver omap1_mbox_driver = {
190 .probe = omap1_mbox_probe,
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700191 .remove = __devexit_p(omap1_mbox_remove),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800192 .driver = {
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700193 .name = "omap1-mailbox",
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800194 },
195};
196
197static int __init omap1_mbox_init(void)
198{
199 return platform_driver_register(&omap1_mbox_driver);
200}
201
202static void __exit omap1_mbox_exit(void)
203{
204 platform_driver_unregister(&omap1_mbox_driver);
205}
206
207module_init(omap1_mbox_init);
208module_exit(omap1_mbox_exit);
209
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700210MODULE_LICENSE("GPL v2");
211MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions");
Jonathan McDowell0c405b32009-06-23 13:30:21 +0300212MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700213MODULE_ALIAS("platform:omap1-mailbox");