]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap1/mailbox.c
ad077afff3ef36ad9184bcf4a2a53702500db5d9
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap1 / mailbox.c
1 /*
2  * Mailbox reservation modules for DSP
3  *
4  * Copyright (C) 2006 Nokia Corporation
5  * 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/config.h>
13 #include <linux/kernel.h>
14 #include <asm/arch/mailbox.h>
15 #include <asm/arch/irqs.h>
16 #include <asm/io.h>
17
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
28 unsigned long mbox_base;
29
30 struct omap_mbox1_fifo {
31         void *cmd;
32         void *data;
33         void *flag;
34 };
35
36 struct omap_mbox1_priv {
37         struct omap_mbox1_fifo tx_fifo;
38         struct omap_mbox1_fifo rx_fifo;
39 };
40
41 static inline int mbox_read_reg(unsigned int reg)
42 {
43         return __raw_readw(mbox_base + reg);
44 }
45
46 static inline void mbox_write_reg(unsigned int val, unsigned int reg)
47 {
48         __raw_writew(val, mbox_base + reg);
49 }
50
51 /* msg */
52 static inline mbox_msg_t omap1_mbox_fifo_read(struct omap_mbox *mbox)
53 {
54         struct omap_mbox1_fifo *fifo = &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
55         mbox_msg_t msg;
56
57         msg = mbox_read_reg(fifo->data);
58         msg |= ((mbox_msg_t) mbox_read_reg(fifo->cmd)) << 16;
59
60         return msg;
61 }
62
63 static inline void omap1_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
64 {
65         struct omap_mbox1_fifo *fifo = &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
66
67         mbox_write_reg(msg & 0xffff, fifo->data);
68         mbox_write_reg(msg >> 16, fifo->cmd);
69 }
70
71 static inline int omap1_mbox_fifo_empty(struct omap_mbox *mbox)
72 {
73         return 0;
74 }
75
76 static inline int omap1_mbox_fifo_full(struct omap_mbox *mbox)
77 {
78         return (mbox_read_reg(fifo->flag));
79 }
80
81 /* irq */
82 static inline void omap1_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
83 {
84         if (irq == IRQ_RX)
85                 enable_irq(mbox->irq);
86 }
87
88 static inline void omap1_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
89 {
90         if (irq == IRQ_RX)
91                 disble_irq(mbox->irq);
92 }
93
94 static inline int omap1_mbox_is_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
95 {
96         if (irq == IRQ_TX)
97                 return 0;
98         return 1;
99 }
100
101 struct omap_mbox_ops omap1_mbox_ops = {
102         .fifo_read = omap1_mbox_fifo_read,
103         .fifo_write = omap1_mbox_fifo_write,
104         .fifo_empty = omap1_mbox_fifo_empty,
105         .fifo_full = omap1_mbox_fifo_full,
106         .enable_irq = omap1_mbox_enable_irq,
107         .disable_irq = omap1_mbox_disable_irq,
108         .is_irq = omap1_mbox_is_irq,
109 };
110
111 /* FIXME: the following struct should be created automatically by the user id  */
112
113 /* DSP */
114 static struct omap_mbox2_priv omap1_mbox_dsp_priv = {
115         .tx_fifo = {
116                 .cmd = (void *)MAILBOX_ARM2DSP1b,
117                 .data = (void *)MAILBOX_ARM2DSP1,
118                 .flag = (void *)MAILBOX_ARM2DSP1_Flag,
119         },
120         .rx_fifo = {
121                 .cmd = (void *)MAILBOX_DSP2ARM1b,
122                 .data = (void *)MAILBOX_DSP2ARM1,
123                 .flag = (void *)MAILBOX_DSP2ARM1_Flag,
124         },
125 };
126
127 struct omap_mbox mbox_dsp_info = {
128         .name = "DSP",
129         .ops = &omap1_mbox_ops,
130         .priv = &omap1_mbox_dsp_priv,
131 };
132
133 static int __init omap1_mbox_probe(struct platform_device *pdev)
134 {
135         struct resource *res;
136         int ret = 0;
137
138         if (pdev->num_resources != 2) {
139                 dev_err(&pdev->dev, "invalid number of resources: %d\n",
140                         pdev->num_resources);
141                 return -ENODEV;
142         }
143
144         /* MBOX base */
145         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
146         if (unlikely(!res)) {
147                 dev_err(&pdev->dev, "invalid mem resource\n");
148                 return -ENODEV;
149         }
150         mbox_base = res->start;
151
152         /* DSP IRQ */
153         res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
154         if (unlikely(!res)) {
155                 dev_err(&pdev->dev, "invalid irq resource\n");
156                 return -ENODEV;
157         }
158         mbox_dsp_info.irq = res->start;
159
160         ret = omap_mbox_register(&mbox_dsp_info);
161
162         return ret;
163 }
164
165 static int omap1_mbox_remove(struct platform_device *pdev)
166 {
167         omap_mbox_unregister(&mbox_dsp_info);
168
169         return 0;
170 }
171
172 static struct platform_driver omap1_mbox_driver = {
173         .probe = omap1_mbox_probe,
174         .remove = omap1_mbox_remove,
175         .driver = {
176                 .name = "mailbox",
177         },
178 };
179
180 static int __init omap1_mbox_init(void)
181 {
182         return platform_driver_register(&omap1_mbox_driver);
183 }
184
185 static void __exit omap1_mbox_exit(void)
186 {
187         platform_driver_unregister(&omap1_mbox_driver);
188 }
189
190 module_init(omap1_mbox_init);
191 module_exit(omap1_mbox_exit);
192
193 MODULE_LICENSE("GPL");