1
2
3
4
5
6
7
8
9
10
11#include <linux/bitops.h>
12#include <linux/clk.h>
13#include <linux/err.h>
14#include <linux/interrupt.h>
15#include <linux/io.h>
16#include <linux/irq.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <linux/remoteproc.h>
21
22#include <mach/clock.h>
23
24#include "remoteproc_internal.h"
25
26static char *da8xx_fw_name;
27module_param(da8xx_fw_name, charp, S_IRUGO);
28MODULE_PARM_DESC(da8xx_fw_name,
29 "Name of DSP firmware file in /lib/firmware (if not specified defaults to 'rproc-dsp-fw')");
30
31
32
33
34
35#define SYSCFG_CHIPSIG0 BIT(0)
36#define SYSCFG_CHIPSIG1 BIT(1)
37#define SYSCFG_CHIPSIG2 BIT(2)
38#define SYSCFG_CHIPSIG3 BIT(3)
39#define SYSCFG_CHIPSIG4 BIT(4)
40
41
42
43
44
45
46
47
48
49
50
51struct da8xx_rproc {
52 struct rproc *rproc;
53 struct clk *dsp_clk;
54 void (*ack_fxn)(struct irq_data *data);
55 struct irq_data *irq_data;
56 void __iomem *chipsig;
57 void __iomem *bootreg;
58 int irq;
59};
60
61
62
63
64
65
66
67static irqreturn_t handle_event(int irq, void *p)
68{
69 struct rproc *rproc = (struct rproc *)p;
70
71
72 rproc_vq_interrupt(rproc, 0);
73 rproc_vq_interrupt(rproc, 1);
74
75 return IRQ_HANDLED;
76}
77
78
79
80
81
82
83
84
85
86
87static irqreturn_t da8xx_rproc_callback(int irq, void *p)
88{
89 struct rproc *rproc = (struct rproc *)p;
90 struct da8xx_rproc *drproc = (struct da8xx_rproc *)rproc->priv;
91 u32 chipsig;
92
93 chipsig = readl(drproc->chipsig);
94 if (chipsig & SYSCFG_CHIPSIG0) {
95
96 writel(SYSCFG_CHIPSIG0, drproc->chipsig + 4);
97
98
99
100
101
102
103
104
105
106
107 drproc->ack_fxn(drproc->irq_data);
108
109 return IRQ_WAKE_THREAD;
110 }
111
112 return IRQ_HANDLED;
113}
114
115static int da8xx_rproc_start(struct rproc *rproc)
116{
117 struct device *dev = rproc->dev.parent;
118 struct da8xx_rproc *drproc = (struct da8xx_rproc *)rproc->priv;
119 struct clk *dsp_clk = drproc->dsp_clk;
120
121
122 if (rproc->bootaddr & 0x3ff) {
123 dev_err(dev, "invalid boot address: must be aligned to 1KB\n");
124
125 return -EINVAL;
126 }
127
128 writel(rproc->bootaddr, drproc->bootreg);
129
130 clk_enable(dsp_clk);
131 davinci_clk_reset_deassert(dsp_clk);
132
133 return 0;
134}
135
136static int da8xx_rproc_stop(struct rproc *rproc)
137{
138 struct da8xx_rproc *drproc = rproc->priv;
139
140 clk_disable(drproc->dsp_clk);
141
142 return 0;
143}
144
145
146static void da8xx_rproc_kick(struct rproc *rproc, int vqid)
147{
148 struct da8xx_rproc *drproc = (struct da8xx_rproc *)rproc->priv;
149
150
151 writel(SYSCFG_CHIPSIG2, drproc->chipsig);
152}
153
154static struct rproc_ops da8xx_rproc_ops = {
155 .start = da8xx_rproc_start,
156 .stop = da8xx_rproc_stop,
157 .kick = da8xx_rproc_kick,
158};
159
160static int reset_assert(struct device *dev)
161{
162 struct clk *dsp_clk;
163
164 dsp_clk = clk_get(dev, NULL);
165 if (IS_ERR(dsp_clk)) {
166 dev_err(dev, "clk_get error: %ld\n", PTR_ERR(dsp_clk));
167 return PTR_ERR(dsp_clk);
168 }
169
170 davinci_clk_reset_assert(dsp_clk);
171 clk_put(dsp_clk);
172
173 return 0;
174}
175
176static int da8xx_rproc_probe(struct platform_device *pdev)
177{
178 struct device *dev = &pdev->dev;
179 struct da8xx_rproc *drproc;
180 struct rproc *rproc;
181 struct irq_data *irq_data;
182 struct resource *bootreg_res;
183 struct resource *chipsig_res;
184 struct clk *dsp_clk;
185 void __iomem *chipsig;
186 void __iomem *bootreg;
187 int irq;
188 int ret;
189
190 irq = platform_get_irq(pdev, 0);
191 if (irq < 0) {
192 dev_err(dev, "platform_get_irq(pdev, 0) error: %d\n", irq);
193 return irq;
194 }
195
196 irq_data = irq_get_irq_data(irq);
197 if (!irq_data) {
198 dev_err(dev, "irq_get_irq_data(%d): NULL\n", irq);
199 return -EINVAL;
200 }
201
202 bootreg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
203 bootreg = devm_ioremap_resource(dev, bootreg_res);
204 if (IS_ERR(bootreg))
205 return PTR_ERR(bootreg);
206
207 chipsig_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
208 chipsig = devm_ioremap_resource(dev, chipsig_res);
209 if (IS_ERR(chipsig))
210 return PTR_ERR(chipsig);
211
212 dsp_clk = devm_clk_get(dev, NULL);
213 if (IS_ERR(dsp_clk)) {
214 dev_err(dev, "clk_get error: %ld\n", PTR_ERR(dsp_clk));
215
216 return PTR_ERR(dsp_clk);
217 }
218
219 rproc = rproc_alloc(dev, "dsp", &da8xx_rproc_ops, da8xx_fw_name,
220 sizeof(*drproc));
221 if (!rproc)
222 return -ENOMEM;
223
224 drproc = rproc->priv;
225 drproc->rproc = rproc;
226 rproc->has_iommu = false;
227
228 platform_set_drvdata(pdev, rproc);
229
230
231 ret = devm_request_threaded_irq(dev, irq, da8xx_rproc_callback,
232 handle_event, 0, "da8xx-remoteproc",
233 rproc);
234 if (ret) {
235 dev_err(dev, "devm_request_threaded_irq error: %d\n", ret);
236 goto free_rproc;
237 }
238
239
240
241
242
243
244 ret = reset_assert(dev);
245 if (ret)
246 goto free_rproc;
247
248 drproc->chipsig = chipsig;
249 drproc->bootreg = bootreg;
250 drproc->ack_fxn = irq_data->chip->irq_ack;
251 drproc->irq_data = irq_data;
252 drproc->irq = irq;
253 drproc->dsp_clk = dsp_clk;
254
255 ret = rproc_add(rproc);
256 if (ret) {
257 dev_err(dev, "rproc_add failed: %d\n", ret);
258 goto free_rproc;
259 }
260
261 return 0;
262
263free_rproc:
264 rproc_put(rproc);
265
266 return ret;
267}
268
269static int da8xx_rproc_remove(struct platform_device *pdev)
270{
271 struct device *dev = &pdev->dev;
272 struct rproc *rproc = platform_get_drvdata(pdev);
273 struct da8xx_rproc *drproc = (struct da8xx_rproc *)rproc->priv;
274
275
276
277
278
279
280
281
282
283 reset_assert(dev);
284
285
286
287
288
289
290 disable_irq(drproc->irq);
291
292 rproc_del(rproc);
293 rproc_put(rproc);
294
295 return 0;
296}
297
298static struct platform_driver da8xx_rproc_driver = {
299 .probe = da8xx_rproc_probe,
300 .remove = da8xx_rproc_remove,
301 .driver = {
302 .name = "davinci-rproc",
303 },
304};
305
306module_platform_driver(da8xx_rproc_driver);
307
308MODULE_LICENSE("GPL v2");
309MODULE_DESCRIPTION("DA8XX Remote Processor control driver");
310