blob: ad1aecdd68af96bb1a80960f52a0267572aebb67 [file] [log] [blame]
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -08001/* linux/arch/arm/mach-msm/dma.c
2 *
3 * Copyright (C) 2007 Google, Inc.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004 * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved.
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -08005 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
Arve Hjønnevågc5541072009-06-25 17:03:14 -070017#include <linux/clk.h>
18#include <linux/err.h>
Russell Kingfced80c2008-09-06 12:10:45 +010019#include <linux/io.h>
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -080020#include <linux/interrupt.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/spinlock.h>
24#include <linux/pm_runtime.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010025#include <mach/dma.h>
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -080026
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027#define MODULE_NAME "msm_dmov"
28
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -080029#define MSM_DMOV_CHANNEL_COUNT 16
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070030#define MSM_DMOV_CRCI_COUNT 16
31
32enum {
33 CLK_DIS,
34 CLK_TO_BE_DIS,
35 CLK_EN
36};
37
38struct msm_dmov_ci_conf {
39 int start;
40 int end;
41 int burst;
42};
43
44struct msm_dmov_crci_conf {
45 int sd;
46 int blk_size;
47};
48
49struct msm_dmov_chan_conf {
50 int sd;
51 int block;
52 int priority;
53};
54
55struct msm_dmov_conf {
56 void *base;
57 struct msm_dmov_crci_conf *crci_conf;
58 struct msm_dmov_chan_conf *chan_conf;
59 int channel_active;
Jeff Ohlstein905f1ce2011-09-07 18:50:18 -070060 int sd;
61 size_t sd_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070062 struct list_head ready_commands[MSM_DMOV_CHANNEL_COUNT];
63 struct list_head active_commands[MSM_DMOV_CHANNEL_COUNT];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064 spinlock_t lock;
65 unsigned int irq;
66 struct clk *clk;
67 struct clk *pclk;
68 struct clk *ebiclk;
69 unsigned int clk_ctl;
70 struct timer_list timer;
71};
72
73static void msm_dmov_clock_timer(unsigned long);
74static int msm_dmov_clk_toggle(int, int);
75
76#ifdef CONFIG_ARCH_MSM8X60
77
78#define DMOV_CHANNEL_DEFAULT_CONF { .sd = 1, .block = 0, .priority = 0 }
79#define DMOV_CHANNEL_MODEM_CONF { .sd = 3, .block = 0, .priority = 0 }
80#define DMOV_CHANNEL_CONF(secd, blk, pri) \
81 { .sd = secd, .block = blk, .priority = pri }
82
83static struct msm_dmov_chan_conf adm0_chan_conf[] = {
84 DMOV_CHANNEL_DEFAULT_CONF,
85 DMOV_CHANNEL_DEFAULT_CONF,
86 DMOV_CHANNEL_DEFAULT_CONF,
87 DMOV_CHANNEL_DEFAULT_CONF,
88 DMOV_CHANNEL_DEFAULT_CONF,
89 DMOV_CHANNEL_DEFAULT_CONF,
90 DMOV_CHANNEL_DEFAULT_CONF,
91 DMOV_CHANNEL_DEFAULT_CONF,
92 DMOV_CHANNEL_DEFAULT_CONF,
93 DMOV_CHANNEL_DEFAULT_CONF,
94 DMOV_CHANNEL_MODEM_CONF,
95 DMOV_CHANNEL_MODEM_CONF,
96 DMOV_CHANNEL_MODEM_CONF,
97 DMOV_CHANNEL_MODEM_CONF,
98 DMOV_CHANNEL_MODEM_CONF,
99 DMOV_CHANNEL_DEFAULT_CONF,
100};
101
102static struct msm_dmov_chan_conf adm1_chan_conf[] = {
103 DMOV_CHANNEL_DEFAULT_CONF,
104 DMOV_CHANNEL_DEFAULT_CONF,
105 DMOV_CHANNEL_DEFAULT_CONF,
106 DMOV_CHANNEL_DEFAULT_CONF,
107 DMOV_CHANNEL_DEFAULT_CONF,
108 DMOV_CHANNEL_DEFAULT_CONF,
109 DMOV_CHANNEL_DEFAULT_CONF,
110 DMOV_CHANNEL_DEFAULT_CONF,
111 DMOV_CHANNEL_DEFAULT_CONF,
112 DMOV_CHANNEL_DEFAULT_CONF,
113 DMOV_CHANNEL_MODEM_CONF,
114 DMOV_CHANNEL_MODEM_CONF,
115 DMOV_CHANNEL_MODEM_CONF,
116 DMOV_CHANNEL_MODEM_CONF,
117 DMOV_CHANNEL_MODEM_CONF,
118 DMOV_CHANNEL_MODEM_CONF,
119};
120
121#define DMOV_CRCI_DEFAULT_CONF { .sd = 1, .blk_size = 0 }
122#define DMOV_CRCI_CONF(secd, blk) { .sd = secd, .blk_size = blk }
123
124static struct msm_dmov_crci_conf adm0_crci_conf[] = {
125 DMOV_CRCI_DEFAULT_CONF,
126 DMOV_CRCI_DEFAULT_CONF,
127 DMOV_CRCI_DEFAULT_CONF,
128 DMOV_CRCI_DEFAULT_CONF,
129 DMOV_CRCI_DEFAULT_CONF,
130 DMOV_CRCI_DEFAULT_CONF,
131 DMOV_CRCI_CONF(1, 4),
132 DMOV_CRCI_DEFAULT_CONF,
133 DMOV_CRCI_DEFAULT_CONF,
134 DMOV_CRCI_DEFAULT_CONF,
135 DMOV_CRCI_DEFAULT_CONF,
136 DMOV_CRCI_DEFAULT_CONF,
137 DMOV_CRCI_DEFAULT_CONF,
138 DMOV_CRCI_DEFAULT_CONF,
139 DMOV_CRCI_DEFAULT_CONF,
140 DMOV_CRCI_DEFAULT_CONF,
141};
142
143static struct msm_dmov_crci_conf adm1_crci_conf[] = {
144 DMOV_CRCI_DEFAULT_CONF,
145 DMOV_CRCI_CONF(1, 1),
146 DMOV_CRCI_CONF(1, 1),
147 DMOV_CRCI_DEFAULT_CONF,
148 DMOV_CRCI_CONF(1, 1),
149 DMOV_CRCI_CONF(1, 1),
150 DMOV_CRCI_DEFAULT_CONF,
151 DMOV_CRCI_DEFAULT_CONF,
152 DMOV_CRCI_DEFAULT_CONF,
153 DMOV_CRCI_DEFAULT_CONF,
154 DMOV_CRCI_DEFAULT_CONF,
155 DMOV_CRCI_DEFAULT_CONF,
156 DMOV_CRCI_DEFAULT_CONF,
157 DMOV_CRCI_DEFAULT_CONF,
158 DMOV_CRCI_CONF(1, 1),
159 DMOV_CRCI_DEFAULT_CONF,
160};
161
162static struct msm_dmov_conf dmov_conf[] = {
163 {
164 .crci_conf = adm0_crci_conf,
165 .chan_conf = adm0_chan_conf,
166 .lock = __SPIN_LOCK_UNLOCKED(dmov_lock),
167 .clk_ctl = CLK_DIS,
168 .timer = TIMER_INITIALIZER(msm_dmov_clock_timer, 0, 0),
169 }, {
170 .crci_conf = adm1_crci_conf,
171 .chan_conf = adm1_chan_conf,
172 .lock = __SPIN_LOCK_UNLOCKED(dmov_lock),
173 .clk_ctl = CLK_DIS,
174 .timer = TIMER_INITIALIZER(msm_dmov_clock_timer, 0, 1),
175 }
176};
177#else
178static struct msm_dmov_conf dmov_conf[] = {
179 {
180 .crci_conf = NULL,
181 .chan_conf = NULL,
182 .lock = __SPIN_LOCK_UNLOCKED(dmov_lock),
183 .clk_ctl = CLK_DIS,
184 .timer = TIMER_INITIALIZER(msm_dmov_clock_timer, 0, 0),
185 }
186};
187#endif
188
189#define MSM_DMOV_ID_COUNT (MSM_DMOV_CHANNEL_COUNT * ARRAY_SIZE(dmov_conf))
Jeff Ohlstein905f1ce2011-09-07 18:50:18 -0700190#define DMOV_REG(name, adm) ((name) + (dmov_conf[adm].base) +\
191 (dmov_conf[adm].sd * dmov_conf[adm].sd_size))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700192#define DMOV_ID_TO_ADM(id) ((id) / MSM_DMOV_CHANNEL_COUNT)
193#define DMOV_ID_TO_CHAN(id) ((id) % MSM_DMOV_CHANNEL_COUNT)
194#define DMOV_CHAN_ADM_TO_ID(ch, adm) ((ch) + (adm) * MSM_DMOV_CHANNEL_COUNT)
195
196#ifdef CONFIG_MSM_ADM3
197#define DMOV_IRQ_TO_ADM(irq) \
198({ \
199 typeof(irq) _irq = irq; \
200 ((_irq == INT_ADM1_MASTER) || (_irq == INT_ADM1_AARM)); \
201})
202#else
203#define DMOV_IRQ_TO_ADM(irq) 0
204#endif
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800205
206enum {
207 MSM_DMOV_PRINT_ERRORS = 1,
208 MSM_DMOV_PRINT_IO = 2,
209 MSM_DMOV_PRINT_FLOW = 4
210};
211
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800212unsigned int msm_dmov_print_mask = MSM_DMOV_PRINT_ERRORS;
213
214#define MSM_DMOV_DPRINTF(mask, format, args...) \
215 do { \
216 if ((mask) & msm_dmov_print_mask) \
217 printk(KERN_ERR format, args); \
218 } while (0)
219#define PRINT_ERROR(format, args...) \
220 MSM_DMOV_DPRINTF(MSM_DMOV_PRINT_ERRORS, format, args);
221#define PRINT_IO(format, args...) \
222 MSM_DMOV_DPRINTF(MSM_DMOV_PRINT_IO, format, args);
223#define PRINT_FLOW(format, args...) \
224 MSM_DMOV_DPRINTF(MSM_DMOV_PRINT_FLOW, format, args);
225
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700226static int msm_dmov_clk_toggle(int adm, int on)
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700227{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700228 int ret = 0;
229
230 if (on) {
231 ret = clk_enable(dmov_conf[adm].clk);
232 if (ret)
233 goto err;
234 if (dmov_conf[adm].pclk) {
235 ret = clk_enable(dmov_conf[adm].pclk);
236 if (ret) {
237 clk_disable(dmov_conf[adm].clk);
238 goto err;
239 }
240 }
241 if (dmov_conf[adm].ebiclk) {
242 ret = clk_enable(dmov_conf[adm].ebiclk);
243 if (ret) {
244 if (dmov_conf[adm].pclk)
245 clk_disable(dmov_conf[adm].pclk);
246 clk_disable(dmov_conf[adm].clk);
247 }
248 }
249 } else {
250 clk_disable(dmov_conf[adm].clk);
251 if (dmov_conf[adm].pclk)
252 clk_disable(dmov_conf[adm].pclk);
253 if (dmov_conf[adm].ebiclk)
254 clk_disable(dmov_conf[adm].ebiclk);
255 }
256err:
257 return ret;
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700258}
259
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700260static void msm_dmov_clock_timer(unsigned long adm)
261{
262 unsigned long irq_flags;
263 spin_lock_irqsave(&dmov_conf[adm].lock, irq_flags);
264 if (dmov_conf[adm].clk_ctl == CLK_TO_BE_DIS) {
265 BUG_ON(dmov_conf[adm].channel_active);
266 msm_dmov_clk_toggle(adm, 0);
267 dmov_conf[adm].clk_ctl = CLK_DIS;
268 }
269 spin_unlock_irqrestore(&dmov_conf[adm].lock, irq_flags);
270}
271
272void msm_dmov_stop_cmd(unsigned id, struct msm_dmov_cmd *cmd, int graceful)
273{
274 int adm = DMOV_ID_TO_ADM(id);
275 int ch = DMOV_ID_TO_CHAN(id);
276 writel_relaxed((graceful << 31), DMOV_REG(DMOV_FLUSH0(ch), adm));
277 wmb();
278}
279EXPORT_SYMBOL(msm_dmov_stop_cmd);
280
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700281void msm_dmov_enqueue_cmd_ext(unsigned id, struct msm_dmov_cmd *cmd)
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800282{
283 unsigned long irq_flags;
284 unsigned int status;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700285 int adm = DMOV_ID_TO_ADM(id);
286 int ch = DMOV_ID_TO_CHAN(id);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800287
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700288 spin_lock_irqsave(&dmov_conf[adm].lock, irq_flags);
289 if (dmov_conf[adm].clk_ctl == CLK_DIS)
290 msm_dmov_clk_toggle(adm, 1);
291 else if (dmov_conf[adm].clk_ctl == CLK_TO_BE_DIS)
292 del_timer(&dmov_conf[adm].timer);
293 dmov_conf[adm].clk_ctl = CLK_EN;
294
295 status = readl_relaxed(DMOV_REG(DMOV_STATUS(ch), adm));
Jeff Ohlsteindc39f972011-09-02 13:55:16 -0700296 if (status & DMOV_STATUS_CMD_PTR_RDY) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700297 PRINT_IO("msm_dmov_enqueue_cmd(%d), start command, status %x\n",
298 id, status);
299 if (cmd->exec_func)
300 cmd->exec_func(cmd);
301 list_add_tail(&cmd->list, &dmov_conf[adm].active_commands[ch]);
302 if (!dmov_conf[adm].channel_active)
303 enable_irq(dmov_conf[adm].irq);
304 dmov_conf[adm].channel_active |= 1U << ch;
305 PRINT_IO("Writing %x exactly to register", cmd->cmdptr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700306 writel_relaxed(cmd->cmdptr, DMOV_REG(DMOV_CMD_PTR(ch), adm));
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800307 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700308 if (!dmov_conf[adm].channel_active) {
309 dmov_conf[adm].clk_ctl = CLK_TO_BE_DIS;
310 mod_timer(&dmov_conf[adm].timer, jiffies + HZ);
311 }
Jeff Ohlsteindc39f972011-09-02 13:55:16 -0700312 if (list_empty(&dmov_conf[adm].active_commands[ch]))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700313 PRINT_ERROR("msm_dmov_enqueue_cmd_ext(%d), stalled, "
314 "status %x\n", id, status);
315 PRINT_IO("msm_dmov_enqueue_cmd(%d), enqueue command, status "
316 "%x\n", id, status);
317 list_add_tail(&cmd->list, &dmov_conf[adm].ready_commands[ch]);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800318 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700319 spin_unlock_irqrestore(&dmov_conf[adm].lock, irq_flags);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800320}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700321EXPORT_SYMBOL(msm_dmov_enqueue_cmd_ext);
322
323void msm_dmov_enqueue_cmd(unsigned id, struct msm_dmov_cmd *cmd)
324{
325 /* Disable callback function (for backwards compatibility) */
326 cmd->exec_func = NULL;
327
328 msm_dmov_enqueue_cmd_ext(id, cmd);
329}
330EXPORT_SYMBOL(msm_dmov_enqueue_cmd);
331
332void msm_dmov_flush(unsigned int id)
333{
334 unsigned long irq_flags;
335 int ch = DMOV_ID_TO_CHAN(id);
336 int adm = DMOV_ID_TO_ADM(id);
337 spin_lock_irqsave(&dmov_conf[adm].lock, irq_flags);
338 /* XXX not checking if flush cmd sent already */
339 if (!list_empty(&dmov_conf[adm].active_commands[ch])) {
340 PRINT_IO("msm_dmov_flush(%d), send flush cmd\n", id);
341 writel_relaxed(DMOV_FLUSH_TYPE, DMOV_REG(DMOV_FLUSH0(ch), adm));
342 }
343 /* spin_unlock_irqrestore has the necessary barrier */
344 spin_unlock_irqrestore(&dmov_conf[adm].lock, irq_flags);
345}
346EXPORT_SYMBOL(msm_dmov_flush);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800347
348struct msm_dmov_exec_cmdptr_cmd {
349 struct msm_dmov_cmd dmov_cmd;
350 struct completion complete;
351 unsigned id;
352 unsigned int result;
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700353 struct msm_dmov_errdata err;
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800354};
355
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700356static void
357dmov_exec_cmdptr_complete_func(struct msm_dmov_cmd *_cmd,
358 unsigned int result,
359 struct msm_dmov_errdata *err)
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800360{
361 struct msm_dmov_exec_cmdptr_cmd *cmd = container_of(_cmd, struct msm_dmov_exec_cmdptr_cmd, dmov_cmd);
362 cmd->result = result;
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700363 if (result != 0x80000002 && err)
364 memcpy(&cmd->err, err, sizeof(struct msm_dmov_errdata));
365
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800366 complete(&cmd->complete);
367}
368
Jeff Ohlsteindc39f972011-09-02 13:55:16 -0700369int msm_dmov_exec_cmd(unsigned id, unsigned int cmdptr)
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800370{
371 struct msm_dmov_exec_cmdptr_cmd cmd;
372
373 PRINT_FLOW("dmov_exec_cmdptr(%d, %x)\n", id, cmdptr);
374
375 cmd.dmov_cmd.cmdptr = cmdptr;
376 cmd.dmov_cmd.complete_func = dmov_exec_cmdptr_complete_func;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700377 cmd.dmov_cmd.exec_func = NULL;
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800378 cmd.id = id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700379 cmd.result = 0;
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800380 init_completion(&cmd.complete);
381
382 msm_dmov_enqueue_cmd(id, &cmd.dmov_cmd);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700383 wait_for_completion_io(&cmd.complete);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800384
385 if (cmd.result != 0x80000002) {
386 PRINT_ERROR("dmov_exec_cmdptr(%d): ERROR, result: %x\n", id, cmd.result);
387 PRINT_ERROR("dmov_exec_cmdptr(%d): flush: %x %x %x %x\n",
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700388 id, cmd.err.flush[0], cmd.err.flush[1], cmd.err.flush[2], cmd.err.flush[3]);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800389 return -EIO;
390 }
391 PRINT_FLOW("dmov_exec_cmdptr(%d, %x) done\n", id, cmdptr);
392 return 0;
393}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700394EXPORT_SYMBOL(msm_dmov_exec_cmd);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800395
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700396static void fill_errdata(struct msm_dmov_errdata *errdata, int ch, int adm)
397{
398 errdata->flush[0] = readl_relaxed(DMOV_REG(DMOV_FLUSH0(ch), adm));
399 errdata->flush[1] = readl_relaxed(DMOV_REG(DMOV_FLUSH1(ch), adm));
400 errdata->flush[2] = readl_relaxed(DMOV_REG(DMOV_FLUSH2(ch), adm));
401 errdata->flush[3] = readl_relaxed(DMOV_REG(DMOV_FLUSH3(ch), adm));
402 errdata->flush[4] = readl_relaxed(DMOV_REG(DMOV_FLUSH4(ch), adm));
403 errdata->flush[5] = readl_relaxed(DMOV_REG(DMOV_FLUSH5(ch), adm));
404}
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800405
406static irqreturn_t msm_datamover_irq_handler(int irq, void *dev_id)
407{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700408 unsigned int int_status;
409 unsigned int mask;
410 unsigned int id;
411 unsigned int ch;
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800412 unsigned long irq_flags;
413 unsigned int ch_status;
414 unsigned int ch_result;
Jeff Ohlstein67b8e4c2011-09-06 18:13:15 -0700415 unsigned int valid = 0;
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800416 struct msm_dmov_cmd *cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700417 int adm = DMOV_IRQ_TO_ADM(irq);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800418
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700419 spin_lock_irqsave(&dmov_conf[adm].lock, irq_flags);
420 /* read and clear isr */
421 int_status = readl_relaxed(DMOV_REG(DMOV_ISR, adm));
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800422 PRINT_FLOW("msm_datamover_irq_handler: DMOV_ISR %x\n", int_status);
423
424 while (int_status) {
425 mask = int_status & -int_status;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700426 ch = fls(mask) - 1;
427 id = DMOV_CHAN_ADM_TO_ID(ch, adm);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800428 PRINT_FLOW("msm_datamover_irq_handler %08x %08x id %d\n", int_status, mask, id);
429 int_status &= ~mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700430 ch_status = readl_relaxed(DMOV_REG(DMOV_STATUS(ch), adm));
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800431 if (!(ch_status & DMOV_STATUS_RSLT_VALID)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700432 PRINT_FLOW("msm_datamover_irq_handler id %d, "
433 "result not valid %x\n", id, ch_status);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800434 continue;
435 }
436 do {
Jeff Ohlstein67b8e4c2011-09-06 18:13:15 -0700437 valid = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700438 ch_result = readl_relaxed(DMOV_REG(DMOV_RSLT(ch), adm));
439 if (list_empty(&dmov_conf[adm].active_commands[ch])) {
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800440 PRINT_ERROR("msm_datamover_irq_handler id %d, got result "
441 "with no active command, status %x, result %x\n",
442 id, ch_status, ch_result);
443 cmd = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700444 } else {
445 cmd = list_entry(dmov_conf[adm].
446 active_commands[ch].next, typeof(*cmd),
447 list);
448 }
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800449 PRINT_FLOW("msm_datamover_irq_handler id %d, status %x, result %x\n", id, ch_status, ch_result);
450 if (ch_result & DMOV_RSLT_DONE) {
451 PRINT_FLOW("msm_datamover_irq_handler id %d, status %x\n",
452 id, ch_status);
453 PRINT_IO("msm_datamover_irq_handler id %d, got result "
454 "for %p, result %x\n", id, cmd, ch_result);
455 if (cmd) {
456 list_del(&cmd->list);
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700457 cmd->complete_func(cmd, ch_result, NULL);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800458 }
459 }
460 if (ch_result & DMOV_RSLT_FLUSH) {
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700461 struct msm_dmov_errdata errdata;
462
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700463 fill_errdata(&errdata, ch, adm);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800464 PRINT_FLOW("msm_datamover_irq_handler id %d, status %x\n", id, ch_status);
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700465 PRINT_FLOW("msm_datamover_irq_handler id %d, flush, result %x, flush0 %x\n", id, ch_result, errdata.flush[0]);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800466 if (cmd) {
467 list_del(&cmd->list);
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700468 cmd->complete_func(cmd, ch_result, &errdata);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800469 }
470 }
471 if (ch_result & DMOV_RSLT_ERROR) {
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700472 struct msm_dmov_errdata errdata;
473
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700474 fill_errdata(&errdata, ch, adm);
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700475
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800476 PRINT_ERROR("msm_datamover_irq_handler id %d, status %x\n", id, ch_status);
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700477 PRINT_ERROR("msm_datamover_irq_handler id %d, error, result %x, flush0 %x\n", id, ch_result, errdata.flush[0]);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800478 if (cmd) {
479 list_del(&cmd->list);
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700480 cmd->complete_func(cmd, ch_result, &errdata);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800481 }
482 /* this does not seem to work, once we get an error */
483 /* the datamover will no longer accept commands */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700484 writel_relaxed(0, DMOV_REG(DMOV_FLUSH0(ch),
485 adm));
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800486 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700487 rmb();
488 ch_status = readl_relaxed(DMOV_REG(DMOV_STATUS(ch),
489 adm));
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800490 PRINT_FLOW("msm_datamover_irq_handler id %d, status %x\n", id, ch_status);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700491 if ((ch_status & DMOV_STATUS_CMD_PTR_RDY) &&
492 !list_empty(&dmov_conf[adm].ready_commands[ch])) {
493 cmd = list_entry(dmov_conf[adm].
494 ready_commands[ch].next, typeof(*cmd),
495 list);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800496 list_del(&cmd->list);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700497 if (cmd->exec_func)
498 cmd->exec_func(cmd);
499 list_add_tail(&cmd->list,
500 &dmov_conf[adm].active_commands[ch]);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800501 PRINT_FLOW("msm_datamover_irq_handler id %d, start command\n", id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700502 writel_relaxed(cmd->cmdptr,
503 DMOV_REG(DMOV_CMD_PTR(ch), adm));
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800504 }
505 } while (ch_status & DMOV_STATUS_RSLT_VALID);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700506 if (list_empty(&dmov_conf[adm].active_commands[ch]) &&
507 list_empty(&dmov_conf[adm].ready_commands[ch]))
508 dmov_conf[adm].channel_active &= ~(1U << ch);
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800509 PRINT_FLOW("msm_datamover_irq_handler id %d, status %x\n", id, ch_status);
510 }
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700511
Jeff Ohlstein67b8e4c2011-09-06 18:13:15 -0700512 if (!dmov_conf[adm].channel_active && valid) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700513 disable_irq_nosync(dmov_conf[adm].irq);
514 dmov_conf[adm].clk_ctl = CLK_TO_BE_DIS;
515 mod_timer(&dmov_conf[adm].timer, jiffies + HZ);
Arve Hjønnevågc5541072009-06-25 17:03:14 -0700516 }
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700517
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700518 spin_unlock_irqrestore(&dmov_conf[adm].lock, irq_flags);
Jeff Ohlstein67b8e4c2011-09-06 18:13:15 -0700519 return valid ? IRQ_HANDLED : IRQ_NONE;
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800520}
521
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700522static int msm_dmov_suspend_late(struct device *dev)
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800523{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700524 unsigned long irq_flags;
525 struct platform_device *pdev = to_platform_device(dev);
526 int adm = (pdev->id >= 0) ? pdev->id : 0;
527 spin_lock_irqsave(&dmov_conf[adm].lock, irq_flags);
528 if (dmov_conf[adm].clk_ctl == CLK_TO_BE_DIS) {
529 BUG_ON(dmov_conf[adm].channel_active);
530 del_timer(&dmov_conf[adm].timer);
531 msm_dmov_clk_toggle(adm, 0);
532 dmov_conf[adm].clk_ctl = CLK_DIS;
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800533 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700534 spin_unlock_irqrestore(&dmov_conf[adm].lock, irq_flags);
Brian Swetland8a0f6f12008-09-10 14:58:25 -0700535 return 0;
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800536}
537
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700538static int msm_dmov_runtime_suspend(struct device *dev)
539{
540 dev_dbg(dev, "pm_runtime: suspending...\n");
541 return 0;
542}
Arve Hjønnevågbfe645a2007-11-26 04:12:29 -0800543
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700544static int msm_dmov_runtime_resume(struct device *dev)
545{
546 dev_dbg(dev, "pm_runtime: resuming...\n");
547 return 0;
548}
549
550static int msm_dmov_runtime_idle(struct device *dev)
551{
552 dev_dbg(dev, "pm_runtime: idling...\n");
553 return 0;
554}
555
556static struct dev_pm_ops msm_dmov_dev_pm_ops = {
557 .runtime_suspend = msm_dmov_runtime_suspend,
558 .runtime_resume = msm_dmov_runtime_resume,
559 .runtime_idle = msm_dmov_runtime_idle,
560 .suspend = msm_dmov_suspend_late,
561};
562
563static int msm_dmov_init_clocks(struct platform_device *pdev)
564{
565 int adm = (pdev->id >= 0) ? pdev->id : 0;
566 int ret;
567
Matt Wagantalle1a86062011-08-18 17:46:10 -0700568 dmov_conf[adm].clk = clk_get(&pdev->dev, "core_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700569 if (IS_ERR(dmov_conf[adm].clk)) {
570 printk(KERN_ERR "%s: Error getting adm_clk\n", __func__);
571 dmov_conf[adm].clk = NULL;
572 return -ENOENT;
573 }
574
Matt Wagantalle1a86062011-08-18 17:46:10 -0700575 dmov_conf[adm].pclk = clk_get(&pdev->dev, "iface_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576 if (IS_ERR(dmov_conf[adm].pclk)) {
577 dmov_conf[adm].pclk = NULL;
578 /* pclk not present on all SoCs, don't bail on failure */
579 }
580
Matt Wagantalle1a86062011-08-18 17:46:10 -0700581 dmov_conf[adm].ebiclk = clk_get(&pdev->dev, "mem_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700582 if (IS_ERR(dmov_conf[adm].ebiclk)) {
583 dmov_conf[adm].ebiclk = NULL;
584 /* ebiclk not present on all SoCs, don't bail on failure */
585 } else {
586 ret = clk_set_rate(dmov_conf[adm].ebiclk, 27000000);
587 if (ret)
588 return -ENOENT;
589 }
590
591 return 0;
592}
593
594static void config_datamover(int adm)
595{
596#ifdef CONFIG_MSM_ADM3
597 int i;
598 for (i = 0; i < MSM_DMOV_CHANNEL_COUNT; i++) {
599 struct msm_dmov_chan_conf *chan_conf =
600 dmov_conf[adm].chan_conf;
601 unsigned conf;
602 /* Only configure scorpion channels */
603 if (chan_conf[i].sd <= 1) {
604 conf = readl_relaxed(DMOV_REG(DMOV_CONF(i), adm));
605 conf &= ~DMOV_CONF_SD(7);
606 conf |= DMOV_CONF_SD(chan_conf[i].sd);
607 writel_relaxed(conf | DMOV_CONF_SHADOW_EN,
608 DMOV_REG(DMOV_CONF(i), adm));
609 }
610 }
611 for (i = 0; i < MSM_DMOV_CRCI_COUNT; i++) {
612 struct msm_dmov_crci_conf *crci_conf =
613 dmov_conf[adm].crci_conf;
614
615 writel_relaxed(DMOV_CRCI_CTL_BLK_SZ(crci_conf[i].blk_size),
616 DMOV_REG(DMOV_CRCI_CTL(i), adm));
617 }
618#endif
619}
620
621static int msm_dmov_probe(struct platform_device *pdev)
622{
623 int adm = (pdev->id >= 0) ? pdev->id : 0;
624 int i;
625 int ret;
Jeff Ohlstein905f1ce2011-09-07 18:50:18 -0700626 struct msm_dmov_pdata *pdata = pdev->dev.platform_data;
627 struct resource *irqres =
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700628 platform_get_resource(pdev, IORESOURCE_IRQ, 0);
Jeff Ohlstein905f1ce2011-09-07 18:50:18 -0700629 struct resource *mres =
630 platform_get_resource(pdev, IORESOURCE_MEM, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700631
Jeff Ohlstein905f1ce2011-09-07 18:50:18 -0700632 if (pdata) {
633 dmov_conf[adm].sd = pdata->sd;
634 dmov_conf[adm].sd_size = pdata->sd_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700635 }
Jeff Ohlstein905f1ce2011-09-07 18:50:18 -0700636 if (!dmov_conf[adm].sd_size)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700637 return -ENXIO;
638
Jeff Ohlstein905f1ce2011-09-07 18:50:18 -0700639 if (!irqres || !irqres->start)
640 return -ENXIO;
641 dmov_conf[adm].irq = irqres->start;
642
643 if (!mres || !mres->start)
644 return -ENXIO;
645 dmov_conf[adm].base = ioremap_nocache(mres->start, resource_size(mres));
646 if (!dmov_conf[adm].base)
647 return -ENOMEM;
648
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700649 ret = request_irq(dmov_conf[adm].irq, msm_datamover_irq_handler,
650 0, "msmdatamover", NULL);
651 if (ret) {
652 PRINT_ERROR("Requesting ADM%d irq %d failed\n", adm,
653 dmov_conf[adm].irq);
Jeff Ohlstein905f1ce2011-09-07 18:50:18 -0700654 goto out_map;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700655 }
656 disable_irq(dmov_conf[adm].irq);
657 ret = msm_dmov_init_clocks(pdev);
658 if (ret) {
659 PRINT_ERROR("Requesting ADM%d clocks failed\n", adm);
Jeff Ohlstein905f1ce2011-09-07 18:50:18 -0700660 goto out_irq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700661 }
Jeff Ohlsteincdbfc182011-08-10 12:08:28 -0700662 ret = msm_dmov_clk_toggle(adm, 1);
663 if (ret) {
664 PRINT_ERROR("Enabling ADM%d clocks failed\n", adm);
Jeff Ohlstein905f1ce2011-09-07 18:50:18 -0700665 goto out_irq;
Jeff Ohlsteincdbfc182011-08-10 12:08:28 -0700666 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700667
668 config_datamover(adm);
669 for (i = 0; i < MSM_DMOV_CHANNEL_COUNT; i++) {
670 INIT_LIST_HEAD(&dmov_conf[adm].ready_commands[i]);
671 INIT_LIST_HEAD(&dmov_conf[adm].active_commands[i]);
672
673 writel_relaxed(DMOV_RSLT_CONF_IRQ_EN
674 | DMOV_RSLT_CONF_FORCE_FLUSH_RSLT,
675 DMOV_REG(DMOV_RSLT_CONF(i), adm));
676 }
677 wmb();
Jeff Ohlsteincdbfc182011-08-10 12:08:28 -0700678 msm_dmov_clk_toggle(adm, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700679 return ret;
Jeff Ohlstein905f1ce2011-09-07 18:50:18 -0700680out_irq:
681 free_irq(dmov_conf[adm].irq, NULL);
682out_map:
683 iounmap(dmov_conf[adm].base);
684 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700685}
686
687static struct platform_driver msm_dmov_driver = {
688 .probe = msm_dmov_probe,
689 .driver = {
690 .name = MODULE_NAME,
691 .owner = THIS_MODULE,
692 .pm = &msm_dmov_dev_pm_ops,
693 },
694};
695
696/* static int __init */
697static int __init msm_init_datamover(void)
698{
699 int ret;
700 ret = platform_driver_register(&msm_dmov_driver);
701 if (ret)
702 return ret;
703 return 0;
704}
705arch_initcall(msm_init_datamover);