This source file includes following definitions.
- omap_rproc_mbox_callback
- omap_rproc_kick
- omap_rproc_start
- omap_rproc_stop
- omap_rproc_probe
- omap_rproc_remove
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/err.h>
19 #include <linux/platform_device.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/remoteproc.h>
22 #include <linux/mailbox_client.h>
23 #include <linux/omap-mailbox.h>
24
25 #include <linux/platform_data/remoteproc-omap.h>
26
27 #include "omap_remoteproc.h"
28 #include "remoteproc_internal.h"
29
30
31
32
33
34
35
36 struct omap_rproc {
37 struct mbox_chan *mbox;
38 struct mbox_client client;
39 struct rproc *rproc;
40 };
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 static void omap_rproc_mbox_callback(struct mbox_client *client, void *data)
57 {
58 struct omap_rproc *oproc = container_of(client, struct omap_rproc,
59 client);
60 struct device *dev = oproc->rproc->dev.parent;
61 const char *name = oproc->rproc->name;
62 u32 msg = (u32)data;
63
64 dev_dbg(dev, "mbox msg: 0x%x\n", msg);
65
66 switch (msg) {
67 case RP_MBOX_CRASH:
68
69 dev_err(dev, "omap rproc %s crashed\n", name);
70 break;
71 case RP_MBOX_ECHO_REPLY:
72 dev_info(dev, "received echo reply from %s\n", name);
73 break;
74 default:
75
76 if (rproc_vq_interrupt(oproc->rproc, msg) == IRQ_NONE)
77 dev_dbg(dev, "no message was found in vqid %d\n", msg);
78 }
79 }
80
81
82 static void omap_rproc_kick(struct rproc *rproc, int vqid)
83 {
84 struct omap_rproc *oproc = rproc->priv;
85 struct device *dev = rproc->dev.parent;
86 int ret;
87
88
89 ret = mbox_send_message(oproc->mbox, (void *)vqid);
90 if (ret < 0)
91 dev_err(dev, "failed to send mailbox message, status = %d\n",
92 ret);
93 }
94
95
96
97
98
99
100
101
102 static int omap_rproc_start(struct rproc *rproc)
103 {
104 struct omap_rproc *oproc = rproc->priv;
105 struct device *dev = rproc->dev.parent;
106 struct platform_device *pdev = to_platform_device(dev);
107 struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
108 int ret;
109 struct mbox_client *client = &oproc->client;
110
111 if (pdata->set_bootaddr)
112 pdata->set_bootaddr(rproc->bootaddr);
113
114 client->dev = dev;
115 client->tx_done = NULL;
116 client->rx_callback = omap_rproc_mbox_callback;
117 client->tx_block = false;
118 client->knows_txdone = false;
119
120 oproc->mbox = omap_mbox_request_channel(client, pdata->mbox_name);
121 if (IS_ERR(oproc->mbox)) {
122 ret = -EBUSY;
123 dev_err(dev, "mbox_request_channel failed: %ld\n",
124 PTR_ERR(oproc->mbox));
125 return ret;
126 }
127
128
129
130
131
132
133
134
135 ret = mbox_send_message(oproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
136 if (ret < 0) {
137 dev_err(dev, "mbox_send_message failed: %d\n", ret);
138 goto put_mbox;
139 }
140
141 ret = pdata->device_enable(pdev);
142 if (ret) {
143 dev_err(dev, "omap_device_enable failed: %d\n", ret);
144 goto put_mbox;
145 }
146
147 return 0;
148
149 put_mbox:
150 mbox_free_channel(oproc->mbox);
151 return ret;
152 }
153
154
155 static int omap_rproc_stop(struct rproc *rproc)
156 {
157 struct device *dev = rproc->dev.parent;
158 struct platform_device *pdev = to_platform_device(dev);
159 struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
160 struct omap_rproc *oproc = rproc->priv;
161 int ret;
162
163 ret = pdata->device_shutdown(pdev);
164 if (ret)
165 return ret;
166
167 mbox_free_channel(oproc->mbox);
168
169 return 0;
170 }
171
172 static const struct rproc_ops omap_rproc_ops = {
173 .start = omap_rproc_start,
174 .stop = omap_rproc_stop,
175 .kick = omap_rproc_kick,
176 };
177
178 static int omap_rproc_probe(struct platform_device *pdev)
179 {
180 struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
181 struct omap_rproc *oproc;
182 struct rproc *rproc;
183 int ret;
184
185 ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
186 if (ret) {
187 dev_err(&pdev->dev, "dma_set_coherent_mask: %d\n", ret);
188 return ret;
189 }
190
191 rproc = rproc_alloc(&pdev->dev, pdata->name, &omap_rproc_ops,
192 pdata->firmware, sizeof(*oproc));
193 if (!rproc)
194 return -ENOMEM;
195
196 oproc = rproc->priv;
197 oproc->rproc = rproc;
198
199 rproc->has_iommu = true;
200
201 platform_set_drvdata(pdev, rproc);
202
203 ret = rproc_add(rproc);
204 if (ret)
205 goto free_rproc;
206
207 return 0;
208
209 free_rproc:
210 rproc_free(rproc);
211 return ret;
212 }
213
214 static int omap_rproc_remove(struct platform_device *pdev)
215 {
216 struct rproc *rproc = platform_get_drvdata(pdev);
217
218 rproc_del(rproc);
219 rproc_free(rproc);
220
221 return 0;
222 }
223
224 static struct platform_driver omap_rproc_driver = {
225 .probe = omap_rproc_probe,
226 .remove = omap_rproc_remove,
227 .driver = {
228 .name = "omap-rproc",
229 },
230 };
231
232 module_platform_driver(omap_rproc_driver);
233
234 MODULE_LICENSE("GPL v2");
235 MODULE_DESCRIPTION("OMAP Remote Processor control driver");