blob: 590ac6688866b37f0004d24779ae8e3231dc8bfb [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
32struct omap_mbox1_fifo {
33 unsigned long cmd;
34 unsigned long data;
35 unsigned long flag;
36};
37
38struct omap_mbox1_priv {
39 struct omap_mbox1_fifo tx_fifo;
40 struct omap_mbox1_fifo rx_fifo;
41};
42
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070043static inline int mbox_read_reg(size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080044{
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070045 return __raw_readw(mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080046}
47
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070048static inline void mbox_write_reg(u32 val, size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080049{
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070050 __raw_writew(val, mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080051}
52
53/* msg */
Tony Lindgrene27a93a2007-12-18 20:58:32 -080054static mbox_msg_t omap1_mbox_fifo_read(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080055{
56 struct omap_mbox1_fifo *fifo =
57 &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
58 mbox_msg_t msg;
59
60 msg = mbox_read_reg(fifo->data);
61 msg |= ((mbox_msg_t) mbox_read_reg(fifo->cmd)) << 16;
62
63 return msg;
64}
65
Tony Lindgrene27a93a2007-12-18 20:58:32 -080066static void
Hiroshi DOYU340a6142006-12-07 15:43:59 -080067omap1_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
68{
69 struct omap_mbox1_fifo *fifo =
70 &((struct omap_mbox1_priv *)mbox->priv)->tx_fifo;
71
72 mbox_write_reg(msg & 0xffff, fifo->data);
73 mbox_write_reg(msg >> 16, fifo->cmd);
74}
75
Tony Lindgrene27a93a2007-12-18 20:58:32 -080076static int omap1_mbox_fifo_empty(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080077{
78 return 0;
79}
80
Tony Lindgrene27a93a2007-12-18 20:58:32 -080081static int omap1_mbox_fifo_full(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080082{
83 struct omap_mbox1_fifo *fifo =
84 &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
85
Felipe Contreras909f9dc2010-06-11 15:51:37 +000086 return mbox_read_reg(fifo->flag);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080087}
88
89/* irq */
Tony Lindgrene27a93a2007-12-18 20:58:32 -080090static void
Hiroshi DOYU340a6142006-12-07 15:43:59 -080091omap1_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
92{
93 if (irq == IRQ_RX)
94 enable_irq(mbox->irq);
95}
96
Tony Lindgrene27a93a2007-12-18 20:58:32 -080097static void
Hiroshi DOYU340a6142006-12-07 15:43:59 -080098omap1_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
99{
100 if (irq == IRQ_RX)
101 disable_irq(mbox->irq);
102}
103
Tony Lindgrene27a93a2007-12-18 20:58:32 -0800104static int
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800105omap1_mbox_is_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
106{
107 if (irq == IRQ_TX)
108 return 0;
109 return 1;
110}
111
112static struct omap_mbox_ops omap1_mbox_ops = {
113 .type = OMAP_MBOX_TYPE1,
114 .fifo_read = omap1_mbox_fifo_read,
115 .fifo_write = omap1_mbox_fifo_write,
116 .fifo_empty = omap1_mbox_fifo_empty,
117 .fifo_full = omap1_mbox_fifo_full,
118 .enable_irq = omap1_mbox_enable_irq,
119 .disable_irq = omap1_mbox_disable_irq,
120 .is_irq = omap1_mbox_is_irq,
121};
122
123/* FIXME: the following struct should be created automatically by the user id */
124
125/* DSP */
126static struct omap_mbox1_priv omap1_mbox_dsp_priv = {
127 .tx_fifo = {
128 .cmd = MAILBOX_ARM2DSP1b,
129 .data = MAILBOX_ARM2DSP1,
130 .flag = MAILBOX_ARM2DSP1_Flag,
131 },
132 .rx_fifo = {
133 .cmd = MAILBOX_DSP2ARM1b,
134 .data = MAILBOX_DSP2ARM1,
135 .flag = MAILBOX_DSP2ARM1_Flag,
136 },
137};
138
139struct omap_mbox mbox_dsp_info = {
140 .name = "dsp",
141 .ops = &omap1_mbox_ops,
142 .priv = &omap1_mbox_dsp_priv,
143};
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800144
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700145static int __devinit omap1_mbox_probe(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800146{
147 struct resource *res;
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000148 int ret;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800149
150 /* MBOX base */
151 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
152 if (unlikely(!res)) {
153 dev_err(&pdev->dev, "invalid mem resource\n");
154 return -ENODEV;
155 }
Felipe Balbid7615852010-02-15 10:03:33 -0800156
157 mbox_base = ioremap(res->start, resource_size(res));
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000158 if (!mbox_base)
159 return -ENOMEM;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800160
161 /* DSP IRQ */
162 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
163 if (unlikely(!res)) {
164 dev_err(&pdev->dev, "invalid irq resource\n");
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000165 ret = -ENODEV;
166 goto err_out;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800167 }
168 mbox_dsp_info.irq = res->start;
169
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000170 ret = omap_mbox_register(&pdev->dev, &mbox_dsp_info);
171 if (ret)
172 goto err_out;
173 return 0;
174
175err_out:
176 iounmap(mbox_base);
177 return ret;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800178}
179
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700180static int __devexit omap1_mbox_remove(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800181{
182 omap_mbox_unregister(&mbox_dsp_info);
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000183 iounmap(mbox_base);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800184 return 0;
185}
186
187static struct platform_driver omap1_mbox_driver = {
188 .probe = omap1_mbox_probe,
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700189 .remove = __devexit_p(omap1_mbox_remove),
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800190 .driver = {
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700191 .name = "omap1-mailbox",
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800192 },
193};
194
195static int __init omap1_mbox_init(void)
196{
197 return platform_driver_register(&omap1_mbox_driver);
198}
199
200static void __exit omap1_mbox_exit(void)
201{
202 platform_driver_unregister(&omap1_mbox_driver);
203}
204
205module_init(omap1_mbox_init);
206module_exit(omap1_mbox_exit);
207
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700208MODULE_LICENSE("GPL v2");
209MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions");
Jonathan McDowell0c405b32009-06-23 13:30:21 +0300210MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700211MODULE_ALIAS("platform:omap1-mailbox");