blob: e962926b67bc48dcd146fab36901971910164556 [file] [log] [blame]
Hiroshi DOYU340a614a2006-12-07 15:43:59 -08001/*
Felipe Contrerasd7427092010-06-11 15:51:48 +00002 * Mailbox reservation modules for OMAP1
Hiroshi DOYU340a614a2006-12-07 15:43:59 -08003 *
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -07004 * Copyright (C) 2006-2009 Nokia Corporation
Hiroshi DOYU340a614a2006-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
Paul Gortmaker73017a52011-07-31 16:14:14 -040012#include <linux/module.h>
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080013#include <linux/interrupt.h>
14#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010015#include <linux/io.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070016#include <plat/mailbox.h>
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080017
18#define MAILBOX_ARM2DSP1 0x00
19#define MAILBOX_ARM2DSP1b 0x04
20#define MAILBOX_DSP2ARM1 0x08
21#define MAILBOX_DSP2ARM1b 0x0c
22#define MAILBOX_DSP2ARM2 0x10
23#define MAILBOX_DSP2ARM2b 0x14
24#define MAILBOX_ARM2DSP1_Flag 0x18
25#define MAILBOX_DSP2ARM1_Flag 0x1c
26#define MAILBOX_DSP2ARM2_Flag 0x20
27
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070028static void __iomem *mbox_base;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080029
30struct omap_mbox1_fifo {
31 unsigned long cmd;
32 unsigned long data;
33 unsigned long flag;
34};
35
36struct omap_mbox1_priv {
37 struct omap_mbox1_fifo tx_fifo;
38 struct omap_mbox1_fifo rx_fifo;
39};
40
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070041static inline int mbox_read_reg(size_t ofs)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080042{
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070043 return __raw_readw(mbox_base + ofs);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080044}
45
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070046static inline void mbox_write_reg(u32 val, size_t ofs)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080047{
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070048 __raw_writew(val, mbox_base + ofs);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080049}
50
51/* msg */
Tony Lindgrene27a93a2007-12-18 20:58:32 -080052static mbox_msg_t omap1_mbox_fifo_read(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080053{
54 struct omap_mbox1_fifo *fifo =
55 &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
56 mbox_msg_t msg;
57
58 msg = mbox_read_reg(fifo->data);
59 msg |= ((mbox_msg_t) mbox_read_reg(fifo->cmd)) << 16;
60
61 return msg;
62}
63
Tony Lindgrene27a93a2007-12-18 20:58:32 -080064static void
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080065omap1_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
66{
67 struct omap_mbox1_fifo *fifo =
68 &((struct omap_mbox1_priv *)mbox->priv)->tx_fifo;
69
70 mbox_write_reg(msg & 0xffff, fifo->data);
71 mbox_write_reg(msg >> 16, fifo->cmd);
72}
73
Tony Lindgrene27a93a2007-12-18 20:58:32 -080074static int omap1_mbox_fifo_empty(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080075{
76 return 0;
77}
78
Tony Lindgrene27a93a2007-12-18 20:58:32 -080079static int omap1_mbox_fifo_full(struct omap_mbox *mbox)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080080{
81 struct omap_mbox1_fifo *fifo =
82 &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
83
Felipe Contreras909f9dc2010-06-11 15:51:37 +000084 return mbox_read_reg(fifo->flag);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080085}
86
87/* irq */
Tony Lindgrene27a93a2007-12-18 20:58:32 -080088static void
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080089omap1_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
90{
91 if (irq == IRQ_RX)
92 enable_irq(mbox->irq);
93}
94
Tony Lindgrene27a93a2007-12-18 20:58:32 -080095static void
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080096omap1_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
97{
98 if (irq == IRQ_RX)
99 disable_irq(mbox->irq);
100}
101
Tony Lindgrene27a93a2007-12-18 20:58:32 -0800102static int
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800103omap1_mbox_is_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
104{
105 if (irq == IRQ_TX)
106 return 0;
107 return 1;
108}
109
110static struct omap_mbox_ops omap1_mbox_ops = {
111 .type = OMAP_MBOX_TYPE1,
112 .fifo_read = omap1_mbox_fifo_read,
113 .fifo_write = omap1_mbox_fifo_write,
114 .fifo_empty = omap1_mbox_fifo_empty,
115 .fifo_full = omap1_mbox_fifo_full,
116 .enable_irq = omap1_mbox_enable_irq,
117 .disable_irq = omap1_mbox_disable_irq,
118 .is_irq = omap1_mbox_is_irq,
119};
120
121/* FIXME: the following struct should be created automatically by the user id */
122
123/* DSP */
124static struct omap_mbox1_priv omap1_mbox_dsp_priv = {
125 .tx_fifo = {
126 .cmd = MAILBOX_ARM2DSP1b,
127 .data = MAILBOX_ARM2DSP1,
128 .flag = MAILBOX_ARM2DSP1_Flag,
129 },
130 .rx_fifo = {
131 .cmd = MAILBOX_DSP2ARM1b,
132 .data = MAILBOX_DSP2ARM1,
133 .flag = MAILBOX_DSP2ARM1_Flag,
134 },
135};
136
Aaro Koskinendba5e192010-11-18 19:59:48 +0200137static struct omap_mbox mbox_dsp_info = {
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800138 .name = "dsp",
139 .ops = &omap1_mbox_ops,
140 .priv = &omap1_mbox_dsp_priv,
141};
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800142
Aaro Koskinendba5e192010-11-18 19:59:48 +0200143static struct omap_mbox *omap1_mboxes[] = { &mbox_dsp_info, NULL };
Felipe Contreras898ee752010-06-11 15:51:45 +0000144
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700145static int __devinit omap1_mbox_probe(struct platform_device *pdev)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800146{
Felipe Contreras898ee752010-06-11 15:51:45 +0000147 struct resource *mem;
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000148 int ret;
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000149 struct omap_mbox **list;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800150
Felipe Contreras898ee752010-06-11 15:51:45 +0000151 list = omap1_mboxes;
Felipe Contreras898ee752010-06-11 15:51:45 +0000152 list[0]->irq = platform_get_irq_byname(pdev, "dsp");
153
154 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
155 mbox_base = ioremap(mem->start, resource_size(mem));
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000156 if (!mbox_base)
157 return -ENOMEM;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800158
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000159 ret = omap_mbox_register(&pdev->dev, list);
160 if (ret) {
161 iounmap(mbox_base);
162 return ret;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800163 }
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000164
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000165 return 0;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800166}
167
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700168static int __devexit omap1_mbox_remove(struct platform_device *pdev)
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800169{
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000170 omap_mbox_unregister();
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000171 iounmap(mbox_base);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800172 return 0;
173}
174
175static struct platform_driver omap1_mbox_driver = {
176 .probe = omap1_mbox_probe,
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700177 .remove = __devexit_p(omap1_mbox_remove),
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800178 .driver = {
Felipe Contrerasd7427092010-06-11 15:51:48 +0000179 .name = "omap-mailbox",
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800180 },
181};
182
183static int __init omap1_mbox_init(void)
184{
185 return platform_driver_register(&omap1_mbox_driver);
186}
187
188static void __exit omap1_mbox_exit(void)
189{
190 platform_driver_unregister(&omap1_mbox_driver);
191}
192
193module_init(omap1_mbox_init);
194module_exit(omap1_mbox_exit);
195
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700196MODULE_LICENSE("GPL v2");
197MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions");
Jonathan McDowell0c405b32009-06-23 13:30:21 +0300198MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700199MODULE_ALIAS("platform:omap1-mailbox");