2 * Mailbox reservation modules for DSP
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/kernel.h>
13 #include <linux/resource.h>
14 #include <linux/interrupt.h>
15 #include <linux/platform_device.h>
17 #include <mach/mailbox.h>
18 #include <mach/irqs.h>
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
30 static void __iomem
*mbox_base
;
32 struct omap_mbox1_fifo
{
38 struct omap_mbox1_priv
{
39 struct omap_mbox1_fifo tx_fifo
;
40 struct omap_mbox1_fifo rx_fifo
;
43 static inline int mbox_read_reg(size_t ofs
)
45 return __raw_readw(mbox_base
+ ofs
);
48 static inline void mbox_write_reg(u32 val
, size_t ofs
)
50 __raw_writew(val
, mbox_base
+ ofs
);
54 static mbox_msg_t
omap1_mbox_fifo_read(struct omap_mbox
*mbox
)
56 struct omap_mbox1_fifo
*fifo
=
57 &((struct omap_mbox1_priv
*)mbox
->priv
)->rx_fifo
;
60 msg
= mbox_read_reg(fifo
->data
);
61 msg
|= ((mbox_msg_t
) mbox_read_reg(fifo
->cmd
)) << 16;
67 omap1_mbox_fifo_write(struct omap_mbox
*mbox
, mbox_msg_t msg
)
69 struct omap_mbox1_fifo
*fifo
=
70 &((struct omap_mbox1_priv
*)mbox
->priv
)->tx_fifo
;
72 mbox_write_reg(msg
& 0xffff, fifo
->data
);
73 mbox_write_reg(msg
>> 16, fifo
->cmd
);
76 static int omap1_mbox_fifo_empty(struct omap_mbox
*mbox
)
81 static int omap1_mbox_fifo_full(struct omap_mbox
*mbox
)
83 struct omap_mbox1_fifo
*fifo
=
84 &((struct omap_mbox1_priv
*)mbox
->priv
)->rx_fifo
;
86 return (mbox_read_reg(fifo
->flag
));
91 omap1_mbox_enable_irq(struct omap_mbox
*mbox
, omap_mbox_type_t irq
)
94 enable_irq(mbox
->irq
);
98 omap1_mbox_disable_irq(struct omap_mbox
*mbox
, omap_mbox_type_t irq
)
101 disable_irq(mbox
->irq
);
105 omap1_mbox_is_irq(struct omap_mbox
*mbox
, omap_mbox_type_t irq
)
112 static 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
,
123 /* FIXME: the following struct should be created automatically by the user id */
126 static struct omap_mbox1_priv omap1_mbox_dsp_priv
= {
128 .cmd
= MAILBOX_ARM2DSP1b
,
129 .data
= MAILBOX_ARM2DSP1
,
130 .flag
= MAILBOX_ARM2DSP1_Flag
,
133 .cmd
= MAILBOX_DSP2ARM1b
,
134 .data
= MAILBOX_DSP2ARM1
,
135 .flag
= MAILBOX_DSP2ARM1_Flag
,
139 struct omap_mbox mbox_dsp_info
= {
141 .ops
= &omap1_mbox_ops
,
142 .priv
= &omap1_mbox_dsp_priv
,
144 EXPORT_SYMBOL(mbox_dsp_info
);
146 static int __devinit
omap1_mbox_probe(struct platform_device
*pdev
)
148 struct resource
*res
;
151 if (pdev
->num_resources
!= 2) {
152 dev_err(&pdev
->dev
, "invalid number of resources: %d\n",
153 pdev
->num_resources
);
158 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
159 if (unlikely(!res
)) {
160 dev_err(&pdev
->dev
, "invalid mem resource\n");
163 mbox_base
= res
->start
;
166 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
167 if (unlikely(!res
)) {
168 dev_err(&pdev
->dev
, "invalid irq resource\n");
171 mbox_dsp_info
.irq
= res
->start
;
173 return omap_mbox_register(&pdev
->dev
, &mbox_dsp_info
);
176 static int __devexit
omap1_mbox_remove(struct platform_device
*pdev
)
178 omap_mbox_unregister(&mbox_dsp_info
);
183 static struct platform_driver omap1_mbox_driver
= {
184 .probe
= omap1_mbox_probe
,
185 .remove
= __devexit_p(omap1_mbox_remove
),
187 .name
= "omap1-mailbox",
191 static int __init
omap1_mbox_init(void)
193 return platform_driver_register(&omap1_mbox_driver
);
196 static void __exit
omap1_mbox_exit(void)
198 platform_driver_unregister(&omap1_mbox_driver
);
201 module_init(omap1_mbox_init
);
202 module_exit(omap1_mbox_exit
);
204 MODULE_LICENSE("GPL v2");
205 MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions");
206 MODULE_AUTHOR("Hiroshi DOYU" <Hiroshi
.DOYU@nokia
.com
>);
207 MODULE_ALIAS("platform:omap1-mailbox");