Commit | Line | Data |
---|---|---|
340a614a | 1 | /* |
d742709e | 2 | * Mailbox reservation modules for OMAP1 |
340a614a | 3 | * |
f98d67a0 | 4 | * Copyright (C) 2006-2009 Nokia Corporation |
340a614a HD |
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 | ||
73017a54 | 12 | #include <linux/module.h> |
340a614a HD |
13 | #include <linux/interrupt.h> |
14 | #include <linux/platform_device.h> | |
fced80c7 | 15 | #include <linux/io.h> |
c869c75c SA |
16 | |
17 | #include "omap-mbox.h" | |
340a614a HD |
18 | |
19 | #define MAILBOX_ARM2DSP1 0x00 | |
20 | #define MAILBOX_ARM2DSP1b 0x04 | |
21 | #define MAILBOX_DSP2ARM1 0x08 | |
22 | #define MAILBOX_DSP2ARM1b 0x0c | |
23 | #define MAILBOX_DSP2ARM2 0x10 | |
24 | #define MAILBOX_DSP2ARM2b 0x14 | |
25 | #define MAILBOX_ARM2DSP1_Flag 0x18 | |
26 | #define MAILBOX_DSP2ARM1_Flag 0x1c | |
27 | #define MAILBOX_DSP2ARM2_Flag 0x20 | |
28 | ||
f98d67a0 | 29 | static void __iomem *mbox_base; |
340a614a HD |
30 | |
31 | struct omap_mbox1_fifo { | |
32 | unsigned long cmd; | |
33 | unsigned long data; | |
34 | unsigned long flag; | |
35 | }; | |
36 | ||
37 | struct omap_mbox1_priv { | |
38 | struct omap_mbox1_fifo tx_fifo; | |
39 | struct omap_mbox1_fifo rx_fifo; | |
40 | }; | |
41 | ||
f98d67a0 | 42 | static inline int mbox_read_reg(size_t ofs) |
340a614a | 43 | { |
f98d67a0 | 44 | return __raw_readw(mbox_base + ofs); |
340a614a HD |
45 | } |
46 | ||
f98d67a0 | 47 | static inline void mbox_write_reg(u32 val, size_t ofs) |
340a614a | 48 | { |
f98d67a0 | 49 | __raw_writew(val, mbox_base + ofs); |
340a614a HD |
50 | } |
51 | ||
52 | /* msg */ | |
e27a93a9 | 53 | static mbox_msg_t omap1_mbox_fifo_read(struct omap_mbox *mbox) |
340a614a HD |
54 | { |
55 | struct omap_mbox1_fifo *fifo = | |
56 | &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo; | |
57 | mbox_msg_t msg; | |
58 | ||
59 | msg = mbox_read_reg(fifo->data); | |
60 | msg |= ((mbox_msg_t) mbox_read_reg(fifo->cmd)) << 16; | |
61 | ||
62 | return msg; | |
63 | } | |
64 | ||
e27a93a9 | 65 | static void |
340a614a HD |
66 | omap1_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg) |
67 | { | |
68 | struct omap_mbox1_fifo *fifo = | |
69 | &((struct omap_mbox1_priv *)mbox->priv)->tx_fifo; | |
70 | ||
71 | mbox_write_reg(msg & 0xffff, fifo->data); | |
72 | mbox_write_reg(msg >> 16, fifo->cmd); | |
73 | } | |
74 | ||
e27a93a9 | 75 | static int omap1_mbox_fifo_empty(struct omap_mbox *mbox) |
340a614a HD |
76 | { |
77 | return 0; | |
78 | } | |
79 | ||
e27a93a9 | 80 | static int omap1_mbox_fifo_full(struct omap_mbox *mbox) |
340a614a HD |
81 | { |
82 | struct omap_mbox1_fifo *fifo = | |
83 | &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo; | |
84 | ||
909f9dc7 | 85 | return mbox_read_reg(fifo->flag); |
340a614a HD |
86 | } |
87 | ||
88 | /* irq */ | |
e27a93a9 | 89 | static void |
f91ca05f | 90 | omap1_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) |
340a614a HD |
91 | { |
92 | if (irq == IRQ_RX) | |
93 | enable_irq(mbox->irq); | |
94 | } | |
95 | ||
e27a93a9 | 96 | static void |
f91ca05f | 97 | omap1_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) |
340a614a HD |
98 | { |
99 | if (irq == IRQ_RX) | |
100 | disable_irq(mbox->irq); | |
101 | } | |
102 | ||
e27a93a9 | 103 | static int |
f91ca05f | 104 | omap1_mbox_is_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) |
340a614a HD |
105 | { |
106 | if (irq == IRQ_TX) | |
107 | return 0; | |
108 | return 1; | |
109 | } | |
110 | ||
111 | static struct omap_mbox_ops omap1_mbox_ops = { | |
112 | .type = OMAP_MBOX_TYPE1, | |
113 | .fifo_read = omap1_mbox_fifo_read, | |
114 | .fifo_write = omap1_mbox_fifo_write, | |
115 | .fifo_empty = omap1_mbox_fifo_empty, | |
116 | .fifo_full = omap1_mbox_fifo_full, | |
117 | .enable_irq = omap1_mbox_enable_irq, | |
118 | .disable_irq = omap1_mbox_disable_irq, | |
119 | .is_irq = omap1_mbox_is_irq, | |
120 | }; | |
121 | ||
122 | /* FIXME: the following struct should be created automatically by the user id */ | |
123 | ||
124 | /* DSP */ | |
125 | static struct omap_mbox1_priv omap1_mbox_dsp_priv = { | |
126 | .tx_fifo = { | |
127 | .cmd = MAILBOX_ARM2DSP1b, | |
128 | .data = MAILBOX_ARM2DSP1, | |
129 | .flag = MAILBOX_ARM2DSP1_Flag, | |
130 | }, | |
131 | .rx_fifo = { | |
132 | .cmd = MAILBOX_DSP2ARM1b, | |
133 | .data = MAILBOX_DSP2ARM1, | |
134 | .flag = MAILBOX_DSP2ARM1_Flag, | |
135 | }, | |
136 | }; | |
137 | ||
dba5e190 | 138 | static struct omap_mbox mbox_dsp_info = { |
340a614a HD |
139 | .name = "dsp", |
140 | .ops = &omap1_mbox_ops, | |
141 | .priv = &omap1_mbox_dsp_priv, | |
142 | }; | |
340a614a | 143 | |
dba5e190 | 144 | static struct omap_mbox *omap1_mboxes[] = { &mbox_dsp_info, NULL }; |
898ee756 | 145 | |
351a102d | 146 | static int omap1_mbox_probe(struct platform_device *pdev) |
340a614a | 147 | { |
898ee756 | 148 | struct resource *mem; |
5f1af5c7 | 149 | int ret; |
9c80c8cd | 150 | struct omap_mbox **list; |
340a614a | 151 | |
898ee756 | 152 | list = omap1_mboxes; |
898ee756 | 153 | list[0]->irq = platform_get_irq_byname(pdev, "dsp"); |
d761585a | 154 | |
898ee756 | 155 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
a41677c6 SA |
156 | if (!mem) |
157 | return -ENOENT; | |
158 | ||
898ee756 | 159 | mbox_base = ioremap(mem->start, resource_size(mem)); |
5f1af5c7 FC |
160 | if (!mbox_base) |
161 | return -ENOMEM; | |
340a614a | 162 | |
9c80c8cd FC |
163 | ret = omap_mbox_register(&pdev->dev, list); |
164 | if (ret) { | |
165 | iounmap(mbox_base); | |
166 | return ret; | |
340a614a | 167 | } |
5f1af5c7 | 168 | |
9c80c8cd | 169 | return 0; |
340a614a HD |
170 | } |
171 | ||
351a102d | 172 | static int omap1_mbox_remove(struct platform_device *pdev) |
340a614a | 173 | { |
9c80c8cd | 174 | omap_mbox_unregister(); |
5f1af5c7 | 175 | iounmap(mbox_base); |
340a614a HD |
176 | return 0; |
177 | } | |
178 | ||
179 | static struct platform_driver omap1_mbox_driver = { | |
180 | .probe = omap1_mbox_probe, | |
351a102d | 181 | .remove = omap1_mbox_remove, |
340a614a | 182 | .driver = { |
d742709e | 183 | .name = "omap-mailbox", |
340a614a HD |
184 | }, |
185 | }; | |
186 | ||
187 | static int __init omap1_mbox_init(void) | |
188 | { | |
189 | return platform_driver_register(&omap1_mbox_driver); | |
190 | } | |
191 | ||
192 | static void __exit omap1_mbox_exit(void) | |
193 | { | |
194 | platform_driver_unregister(&omap1_mbox_driver); | |
195 | } | |
196 | ||
197 | module_init(omap1_mbox_init); | |
198 | module_exit(omap1_mbox_exit); | |
199 | ||
f98d67a0 HD |
200 | MODULE_LICENSE("GPL v2"); |
201 | MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions"); | |
0c405b33 | 202 | MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>"); |
f98d67a0 | 203 | MODULE_ALIAS("platform:omap1-mailbox"); |