2 * Mailbox reservation modules for OMAP1
4 * Copyright (C) 2006-2009 Nokia Corporation
5 * Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
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
12 #include <linux/module.h>
13 #include <linux/interrupt.h>
14 #include <linux/platform_device.h>
16 #include <plat/mailbox.h>
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
28 static void __iomem
*mbox_base
;
30 struct omap_mbox1_fifo
{
36 struct omap_mbox1_priv
{
37 struct omap_mbox1_fifo tx_fifo
;
38 struct omap_mbox1_fifo rx_fifo
;
41 static inline int mbox_read_reg(size_t ofs
)
43 return __raw_readw(mbox_base
+ ofs
);
46 static inline void mbox_write_reg(u32 val
, size_t ofs
)
48 __raw_writew(val
, mbox_base
+ ofs
);
52 static mbox_msg_t
omap1_mbox_fifo_read(struct omap_mbox
*mbox
)
54 struct omap_mbox1_fifo
*fifo
=
55 &((struct omap_mbox1_priv
*)mbox
->priv
)->rx_fifo
;
58 msg
= mbox_read_reg(fifo
->data
);
59 msg
|= ((mbox_msg_t
) mbox_read_reg(fifo
->cmd
)) << 16;
65 omap1_mbox_fifo_write(struct omap_mbox
*mbox
, mbox_msg_t msg
)
67 struct omap_mbox1_fifo
*fifo
=
68 &((struct omap_mbox1_priv
*)mbox
->priv
)->tx_fifo
;
70 mbox_write_reg(msg
& 0xffff, fifo
->data
);
71 mbox_write_reg(msg
>> 16, fifo
->cmd
);
74 static int omap1_mbox_fifo_empty(struct omap_mbox
*mbox
)
79 static int omap1_mbox_fifo_full(struct omap_mbox
*mbox
)
81 struct omap_mbox1_fifo
*fifo
=
82 &((struct omap_mbox1_priv
*)mbox
->priv
)->rx_fifo
;
84 return mbox_read_reg(fifo
->flag
);
89 omap1_mbox_enable_irq(struct omap_mbox
*mbox
, omap_mbox_type_t irq
)
92 enable_irq(mbox
->irq
);
96 omap1_mbox_disable_irq(struct omap_mbox
*mbox
, omap_mbox_type_t irq
)
99 disable_irq(mbox
->irq
);
103 omap1_mbox_is_irq(struct omap_mbox
*mbox
, omap_mbox_type_t irq
)
110 static 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
,
121 /* FIXME: the following struct should be created automatically by the user id */
124 static struct omap_mbox1_priv omap1_mbox_dsp_priv
= {
126 .cmd
= MAILBOX_ARM2DSP1b
,
127 .data
= MAILBOX_ARM2DSP1
,
128 .flag
= MAILBOX_ARM2DSP1_Flag
,
131 .cmd
= MAILBOX_DSP2ARM1b
,
132 .data
= MAILBOX_DSP2ARM1
,
133 .flag
= MAILBOX_DSP2ARM1_Flag
,
137 static struct omap_mbox mbox_dsp_info
= {
139 .ops
= &omap1_mbox_ops
,
140 .priv
= &omap1_mbox_dsp_priv
,
143 static struct omap_mbox
*omap1_mboxes
[] = { &mbox_dsp_info
, NULL
};
145 static int omap1_mbox_probe(struct platform_device
*pdev
)
147 struct resource
*mem
;
149 struct omap_mbox
**list
;
152 list
[0]->irq
= platform_get_irq_byname(pdev
, "dsp");
154 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
155 mbox_base
= ioremap(mem
->start
, resource_size(mem
));
159 ret
= omap_mbox_register(&pdev
->dev
, list
);
168 static int omap1_mbox_remove(struct platform_device
*pdev
)
170 omap_mbox_unregister();
175 static struct platform_driver omap1_mbox_driver
= {
176 .probe
= omap1_mbox_probe
,
177 .remove
= omap1_mbox_remove
,
179 .name
= "omap-mailbox",
183 static int __init
omap1_mbox_init(void)
185 return platform_driver_register(&omap1_mbox_driver
);
188 static void __exit
omap1_mbox_exit(void)
190 platform_driver_unregister(&omap1_mbox_driver
);
193 module_init(omap1_mbox_init
);
194 module_exit(omap1_mbox_exit
);
196 MODULE_LICENSE("GPL v2");
197 MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions");
198 MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
199 MODULE_ALIAS("platform:omap1-mailbox");