blob: 18e757a9ec6bf2ed9be244aa6cf182938172c8ed [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
2 * linux/arch/arm/plat-omap/dma.c
3 *
4 * Copyright (C) 2003 Nokia Corporation
Jan Engelhardt96de0e22007-10-19 23:21:04 +02005 * Author: Juha Yrjölä <juha.yrjola@nokia.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01006 * DMA channel linking for 1610 by Samuel Ortiz <samuel.ortiz@nokia.com>
7 * Graphics DMA and LCD DMA graphics tranformations
8 * by Imre Deak <imre.deak@nokia.com>
Anand Gadiyarf8151e52007-12-01 12:14:11 -08009 * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000010 * Merged to support both OMAP1 and OMAP2 by Tony Lindgren <tony@atomide.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010011 * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
12 *
13 * Support functions for the OMAP internal DMA channels.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License version 2 as
17 * published by the Free Software Foundation.
18 *
19 */
20
21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/sched.h>
24#include <linux/spinlock.h>
25#include <linux/errno.h>
26#include <linux/interrupt.h>
Thomas Gleixner418ca1f2006-07-01 22:32:41 +010027#include <linux/irq.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010028
29#include <asm/system.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010030#include <asm/hardware.h>
31#include <asm/dma.h>
32#include <asm/io.h>
33
34#include <asm/arch/tc.h>
35
Anand Gadiyarf8151e52007-12-01 12:14:11 -080036#undef DEBUG
37
38#ifndef CONFIG_ARCH_OMAP1
39enum { DMA_CH_ALLOC_DONE, DMA_CH_PARAMS_SET_DONE, DMA_CH_STARTED,
40 DMA_CH_QUEUED, DMA_CH_NOTSTARTED, DMA_CH_PAUSED, DMA_CH_LINK_ENABLED
41};
42
43enum { DMA_CHAIN_STARTED, DMA_CHAIN_NOTSTARTED };
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000044#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010045
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000046#define OMAP_DMA_ACTIVE 0x01
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010047#define OMAP_DMA_CCR_EN (1 << 7)
Tony Lindgren7ff879d2006-06-26 16:16:15 -070048#define OMAP2_DMA_CSR_CLEAR_MASK 0xffe
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010049
50#define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec)
51
52static int enable_1510_mode = 0;
53
54struct omap_dma_lch {
55 int next_lch;
56 int dev_id;
57 u16 saved_csr;
58 u16 enabled_irqs;
59 const char *dev_name;
60 void (* callback)(int lch, u16 ch_status, void *data);
61 void *data;
Anand Gadiyarf8151e52007-12-01 12:14:11 -080062
63#ifndef CONFIG_ARCH_OMAP1
64 /* required for Dynamic chaining */
65 int prev_linked_ch;
66 int next_linked_ch;
67 int state;
68 int chain_id;
69
70 int status;
71#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010072 long flags;
73};
74
Anand Gadiyarf8151e52007-12-01 12:14:11 -080075struct dma_link_info {
76 int *linked_dmach_q;
77 int no_of_lchs_linked;
78
79 int q_count;
80 int q_tail;
81 int q_head;
82
83 int chain_state;
84 int chain_mode;
85
86};
87
Tony Lindgren4d963722008-07-03 12:24:31 +030088static struct dma_link_info *dma_linked_lch;
89
90#ifndef CONFIG_ARCH_OMAP1
Anand Gadiyarf8151e52007-12-01 12:14:11 -080091
92/* Chain handling macros */
93#define OMAP_DMA_CHAIN_QINIT(chain_id) \
94 do { \
95 dma_linked_lch[chain_id].q_head = \
96 dma_linked_lch[chain_id].q_tail = \
97 dma_linked_lch[chain_id].q_count = 0; \
98 } while (0)
99#define OMAP_DMA_CHAIN_QFULL(chain_id) \
100 (dma_linked_lch[chain_id].no_of_lchs_linked == \
101 dma_linked_lch[chain_id].q_count)
102#define OMAP_DMA_CHAIN_QLAST(chain_id) \
103 do { \
104 ((dma_linked_lch[chain_id].no_of_lchs_linked-1) == \
105 dma_linked_lch[chain_id].q_count) \
106 } while (0)
107#define OMAP_DMA_CHAIN_QEMPTY(chain_id) \
108 (0 == dma_linked_lch[chain_id].q_count)
109#define __OMAP_DMA_CHAIN_INCQ(end) \
110 ((end) = ((end)+1) % dma_linked_lch[chain_id].no_of_lchs_linked)
111#define OMAP_DMA_CHAIN_INCQHEAD(chain_id) \
112 do { \
113 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_head); \
114 dma_linked_lch[chain_id].q_count--; \
115 } while (0)
116
117#define OMAP_DMA_CHAIN_INCQTAIL(chain_id) \
118 do { \
119 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_tail); \
120 dma_linked_lch[chain_id].q_count++; \
121 } while (0)
122#endif
Tony Lindgren4d963722008-07-03 12:24:31 +0300123
124static int dma_lch_count;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100125static int dma_chan_count;
126
127static spinlock_t dma_chan_lock;
Tony Lindgren4d963722008-07-03 12:24:31 +0300128static struct omap_dma_lch *dma_chan;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300129static void __iomem *omap_dma_base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100130
Tony Lindgren4d963722008-07-03 12:24:31 +0300131static const u8 omap1_dma_irq[OMAP1_LOGICAL_DMA_CH_COUNT] = {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100132 INT_DMA_CH0_6, INT_DMA_CH1_7, INT_DMA_CH2_8, INT_DMA_CH3,
133 INT_DMA_CH4, INT_DMA_CH5, INT_1610_DMA_CH6, INT_1610_DMA_CH7,
134 INT_1610_DMA_CH8, INT_1610_DMA_CH9, INT_1610_DMA_CH10,
135 INT_1610_DMA_CH11, INT_1610_DMA_CH12, INT_1610_DMA_CH13,
136 INT_1610_DMA_CH14, INT_1610_DMA_CH15, INT_DMA_LCD
137};
138
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800139static inline void disable_lnk(int lch);
140static void omap_disable_channel_irq(int lch);
141static inline void omap_enable_channel_irq(int lch);
142
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000143#define REVISIT_24XX() printk(KERN_ERR "FIXME: no %s on 24xx\n", \
Harvey Harrison8e86f422008-03-04 15:08:02 -0800144 __func__);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000145
Tony Lindgren0499bde2008-07-03 12:24:36 +0300146#define dma_read(reg) \
147({ \
148 u32 __val; \
149 if (cpu_class_is_omap1()) \
150 __val = __raw_readw(omap_dma_base + OMAP1_DMA_##reg); \
151 else \
152 __val = __raw_readl(omap_dma_base + OMAP_DMA4_##reg); \
153 __val; \
154})
155
156#define dma_write(val, reg) \
157({ \
158 if (cpu_class_is_omap1()) \
159 __raw_writew((u16)(val), omap_dma_base + OMAP1_DMA_##reg); \
160 else \
161 __raw_writel((val), omap_dma_base + OMAP_DMA4_##reg); \
162})
163
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000164#ifdef CONFIG_ARCH_OMAP15XX
165/* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */
166int omap_dma_in_1510_mode(void)
167{
168 return enable_1510_mode;
169}
170#else
171#define omap_dma_in_1510_mode() 0
172#endif
173
174#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100175static inline int get_gdma_dev(int req)
176{
177 u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
178 int shift = ((req - 1) % 5) * 6;
179
180 return ((omap_readl(reg) >> shift) & 0x3f) + 1;
181}
182
183static inline void set_gdma_dev(int req, int dev)
184{
185 u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
186 int shift = ((req - 1) % 5) * 6;
187 u32 l;
188
189 l = omap_readl(reg);
190 l &= ~(0x3f << shift);
191 l |= (dev - 1) << shift;
192 omap_writel(l, reg);
193}
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000194#else
195#define set_gdma_dev(req, dev) do {} while (0)
196#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100197
Tony Lindgren0499bde2008-07-03 12:24:36 +0300198/* Omap1 only */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100199static void clear_lch_regs(int lch)
200{
201 int i;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300202 void __iomem *lch_base = omap_dma_base + OMAP1_DMA_CH_BASE(lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100203
204 for (i = 0; i < 0x2c; i += 2)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300205 __raw_writew(0, lch_base + i);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100206}
207
Tony Lindgren709eb3e2006-09-25 12:45:45 +0300208void omap_set_dma_priority(int lch, int dst_port, int priority)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100209{
210 unsigned long reg;
211 u32 l;
212
Tony Lindgren709eb3e2006-09-25 12:45:45 +0300213 if (cpu_class_is_omap1()) {
214 switch (dst_port) {
215 case OMAP_DMA_PORT_OCP_T1: /* FFFECC00 */
216 reg = OMAP_TC_OCPT1_PRIOR;
217 break;
218 case OMAP_DMA_PORT_OCP_T2: /* FFFECCD0 */
219 reg = OMAP_TC_OCPT2_PRIOR;
220 break;
221 case OMAP_DMA_PORT_EMIFF: /* FFFECC08 */
222 reg = OMAP_TC_EMIFF_PRIOR;
223 break;
224 case OMAP_DMA_PORT_EMIFS: /* FFFECC04 */
225 reg = OMAP_TC_EMIFS_PRIOR;
226 break;
227 default:
228 BUG();
229 return;
230 }
231 l = omap_readl(reg);
232 l &= ~(0xf << 8);
233 l |= (priority & 0xf) << 8;
234 omap_writel(l, reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100235 }
Tony Lindgren709eb3e2006-09-25 12:45:45 +0300236
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800237 if (cpu_class_is_omap2()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300238 u32 ccr;
239
240 ccr = dma_read(CCR(lch));
Tony Lindgren709eb3e2006-09-25 12:45:45 +0300241 if (priority)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300242 ccr |= (1 << 6);
Tony Lindgren709eb3e2006-09-25 12:45:45 +0300243 else
Tony Lindgren0499bde2008-07-03 12:24:36 +0300244 ccr &= ~(1 << 6);
245 dma_write(ccr, CCR(lch));
Tony Lindgren709eb3e2006-09-25 12:45:45 +0300246 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100247}
248
249void omap_set_dma_transfer_params(int lch, int data_type, int elem_count,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000250 int frame_count, int sync_mode,
251 int dma_trigger, int src_or_dst_synch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100252{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300253 u32 l;
254
255 l = dma_read(CSDP(lch));
256 l &= ~0x03;
257 l |= data_type;
258 dma_write(l, CSDP(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100259
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000260 if (cpu_class_is_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300261 u16 ccr;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100262
Tony Lindgren0499bde2008-07-03 12:24:36 +0300263 ccr = dma_read(CCR(lch));
264 ccr &= ~(1 << 5);
265 if (sync_mode == OMAP_DMA_SYNC_FRAME)
266 ccr |= 1 << 5;
267 dma_write(ccr, CCR(lch));
268
269 ccr = dma_read(CCR2(lch));
270 ccr &= ~(1 << 2);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000271 if (sync_mode == OMAP_DMA_SYNC_BLOCK)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300272 ccr |= 1 << 2;
273 dma_write(ccr, CCR2(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000274 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100275
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800276 if (cpu_class_is_omap2() && dma_trigger) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300277 u32 val;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100278
Tony Lindgren0499bde2008-07-03 12:24:36 +0300279 val = dma_read(CCR(lch));
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700280 val &= ~(3 << 19);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000281 if (dma_trigger > 63)
282 val |= 1 << 20;
283 if (dma_trigger > 31)
284 val |= 1 << 19;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100285
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700286 val &= ~(0x1f);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000287 val |= (dma_trigger & 0x1f);
288
289 if (sync_mode & OMAP_DMA_SYNC_FRAME)
290 val |= 1 << 5;
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700291 else
292 val &= ~(1 << 5);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000293
294 if (sync_mode & OMAP_DMA_SYNC_BLOCK)
295 val |= 1 << 18;
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700296 else
297 val &= ~(1 << 18);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000298
299 if (src_or_dst_synch)
300 val |= 1 << 24; /* source synch */
301 else
302 val &= ~(1 << 24); /* dest synch */
303
Tony Lindgren0499bde2008-07-03 12:24:36 +0300304 dma_write(val, CCR(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000305 }
306
Tony Lindgren0499bde2008-07-03 12:24:36 +0300307 dma_write(elem_count, CEN(lch));
308 dma_write(frame_count, CFN(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100309}
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000310
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100311void omap_set_dma_color_mode(int lch, enum omap_dma_color_mode mode, u32 color)
312{
313 u16 w;
314
315 BUG_ON(omap_dma_in_1510_mode());
316
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800317 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000318 REVISIT_24XX();
319 return;
320 }
321
Tony Lindgren0499bde2008-07-03 12:24:36 +0300322 w = dma_read(CCR2(lch));
323 w &= ~0x03;
324
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100325 switch (mode) {
326 case OMAP_DMA_CONSTANT_FILL:
327 w |= 0x01;
328 break;
329 case OMAP_DMA_TRANSPARENT_COPY:
330 w |= 0x02;
331 break;
332 case OMAP_DMA_COLOR_DIS:
333 break;
334 default:
335 BUG();
336 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300337 dma_write(w, CCR2(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100338
Tony Lindgren0499bde2008-07-03 12:24:36 +0300339 w = dma_read(LCH_CTRL(lch));
340 w &= ~0x0f;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100341 /* Default is channel type 2D */
342 if (mode) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300343 dma_write((u16)color, COLOR_L(lch));
344 dma_write((u16)(color >> 16), COLOR_U(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100345 w |= 1; /* Channel type G */
346 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300347 dma_write(w, LCH_CTRL(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100348}
349
Tony Lindgren709eb3e2006-09-25 12:45:45 +0300350void omap_set_dma_write_mode(int lch, enum omap_dma_write_mode mode)
351{
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800352 if (cpu_class_is_omap2()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300353 u32 csdp;
354
355 csdp = dma_read(CSDP(lch));
356 csdp &= ~(0x3 << 16);
357 csdp |= (mode << 16);
358 dma_write(csdp, CSDP(lch));
Tony Lindgren709eb3e2006-09-25 12:45:45 +0300359 }
360}
361
Tony Lindgren0499bde2008-07-03 12:24:36 +0300362void omap_set_dma_channel_mode(int lch, enum omap_dma_channel_mode mode)
363{
364 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
365 u32 l;
366
367 l = dma_read(LCH_CTRL(lch));
368 l &= ~0x7;
369 l |= mode;
370 dma_write(l, LCH_CTRL(lch));
371 }
372}
373EXPORT_SYMBOL(omap_set_dma_channel_mode);
374
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000375/* Note that src_port is only for omap1 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100376void omap_set_dma_src_params(int lch, int src_port, int src_amode,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000377 unsigned long src_start,
378 int src_ei, int src_fi)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100379{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000380 if (cpu_class_is_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300381 u16 w;
382
383 w = dma_read(CSDP(lch));
384 w &= ~(0x1f << 2);
385 w |= src_port << 2;
386 dma_write(w, CSDP(lch));
387
388 w = dma_read(CCR(lch));
389 w &= ~(0x03 << 12);
390 w |= src_amode << 12;
391 dma_write(w, CCR(lch));
392
393 dma_write(src_start >> 16, CSSA_U(lch));
394 dma_write((u16)src_start, CSSA_L(lch));
395
396 dma_write(src_ei, CSEI(lch));
397 dma_write(src_fi, CSFI(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000398 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100399
Tony Lindgren0499bde2008-07-03 12:24:36 +0300400 if (cpu_class_is_omap2()) {
401 u32 l;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100402
Tony Lindgren0499bde2008-07-03 12:24:36 +0300403 l = dma_read(CCR(lch));
404 l &= ~(0x03 << 12);
405 l |= src_amode << 12;
406 dma_write(l, CCR(lch));
407
408 dma_write(src_start, CSSA(lch));
409 dma_write(src_ei, CSEI(lch));
410 dma_write(src_fi, CSFI(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000411 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000412}
413
414void omap_set_dma_params(int lch, struct omap_dma_channel_params * params)
415{
416 omap_set_dma_transfer_params(lch, params->data_type,
417 params->elem_count, params->frame_count,
418 params->sync_mode, params->trigger,
419 params->src_or_dst_synch);
420 omap_set_dma_src_params(lch, params->src_port,
421 params->src_amode, params->src_start,
422 params->src_ei, params->src_fi);
423
424 omap_set_dma_dest_params(lch, params->dst_port,
425 params->dst_amode, params->dst_start,
426 params->dst_ei, params->dst_fi);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800427 if (params->read_prio || params->write_prio)
428 omap_dma_set_prio_lch(lch, params->read_prio,
429 params->write_prio);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100430}
431
432void omap_set_dma_src_index(int lch, int eidx, int fidx)
433{
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800434 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000435 REVISIT_24XX();
436 return;
437 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300438 dma_write(eidx, CSEI(lch));
439 dma_write(fidx, CSFI(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100440}
441
442void omap_set_dma_src_data_pack(int lch, int enable)
443{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300444 u32 l;
445
446 l = dma_read(CSDP(lch));
447 l &= ~(1 << 6);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000448 if (enable)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300449 l |= (1 << 6);
450 dma_write(l, CSDP(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100451}
452
453void omap_set_dma_src_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
454{
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700455 unsigned int burst = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300456 u32 l;
457
458 l = dma_read(CSDP(lch));
459 l &= ~(0x03 << 7);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100460
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100461 switch (burst_mode) {
462 case OMAP_DMA_DATA_BURST_DIS:
463 break;
464 case OMAP_DMA_DATA_BURST_4:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800465 if (cpu_class_is_omap2())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700466 burst = 0x1;
467 else
468 burst = 0x2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100469 break;
470 case OMAP_DMA_DATA_BURST_8:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800471 if (cpu_class_is_omap2()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700472 burst = 0x2;
473 break;
474 }
475 /* not supported by current hardware on OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100476 * w |= (0x03 << 7);
477 * fall through
478 */
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700479 case OMAP_DMA_DATA_BURST_16:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800480 if (cpu_class_is_omap2()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700481 burst = 0x3;
482 break;
483 }
484 /* OMAP1 don't support burst 16
485 * fall through
486 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100487 default:
488 BUG();
489 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300490
491 l |= (burst << 7);
492 dma_write(l, CSDP(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100493}
494
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000495/* Note that dest_port is only for OMAP1 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100496void omap_set_dma_dest_params(int lch, int dest_port, int dest_amode,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000497 unsigned long dest_start,
498 int dst_ei, int dst_fi)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100499{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300500 u32 l;
501
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000502 if (cpu_class_is_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300503 l = dma_read(CSDP(lch));
504 l &= ~(0x1f << 9);
505 l |= dest_port << 9;
506 dma_write(l, CSDP(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000507 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100508
Tony Lindgren0499bde2008-07-03 12:24:36 +0300509 l = dma_read(CCR(lch));
510 l &= ~(0x03 << 14);
511 l |= dest_amode << 14;
512 dma_write(l, CCR(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100513
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000514 if (cpu_class_is_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300515 dma_write(dest_start >> 16, CDSA_U(lch));
516 dma_write(dest_start, CDSA_L(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000517 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100518
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800519 if (cpu_class_is_omap2())
Tony Lindgren0499bde2008-07-03 12:24:36 +0300520 dma_write(dest_start, CDSA(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000521
Tony Lindgren0499bde2008-07-03 12:24:36 +0300522 dma_write(dst_ei, CDEI(lch));
523 dma_write(dst_fi, CDFI(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100524}
525
526void omap_set_dma_dest_index(int lch, int eidx, int fidx)
527{
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800528 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000529 REVISIT_24XX();
530 return;
531 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300532 dma_write(eidx, CDEI(lch));
533 dma_write(fidx, CDFI(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100534}
535
536void omap_set_dma_dest_data_pack(int lch, int enable)
537{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300538 u32 l;
539
540 l = dma_read(CSDP(lch));
541 l &= ~(1 << 13);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000542 if (enable)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300543 l |= 1 << 13;
544 dma_write(l, CSDP(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100545}
546
547void omap_set_dma_dest_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
548{
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700549 unsigned int burst = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300550 u32 l;
551
552 l = dma_read(CSDP(lch));
553 l &= ~(0x03 << 14);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100554
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100555 switch (burst_mode) {
556 case OMAP_DMA_DATA_BURST_DIS:
557 break;
558 case OMAP_DMA_DATA_BURST_4:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800559 if (cpu_class_is_omap2())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700560 burst = 0x1;
561 else
562 burst = 0x2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100563 break;
564 case OMAP_DMA_DATA_BURST_8:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800565 if (cpu_class_is_omap2())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700566 burst = 0x2;
567 else
568 burst = 0x3;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100569 break;
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700570 case OMAP_DMA_DATA_BURST_16:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800571 if (cpu_class_is_omap2()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700572 burst = 0x3;
573 break;
574 }
575 /* OMAP1 don't support burst 16
576 * fall through
577 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100578 default:
579 printk(KERN_ERR "Invalid DMA burst mode\n");
580 BUG();
581 return;
582 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300583 l |= (burst << 14);
584 dma_write(l, CSDP(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100585}
586
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000587static inline void omap_enable_channel_irq(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100588{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000589 u32 status;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100590
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700591 /* Clear CSR */
592 if (cpu_class_is_omap1())
Tony Lindgren0499bde2008-07-03 12:24:36 +0300593 status = dma_read(CSR(lch));
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800594 else if (cpu_class_is_omap2())
Tony Lindgren0499bde2008-07-03 12:24:36 +0300595 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000596
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100597 /* Enable some nice interrupts. */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300598 dma_write(dma_chan[lch].enabled_irqs, CICR(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100599}
600
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000601static void omap_disable_channel_irq(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100602{
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800603 if (cpu_class_is_omap2())
Tony Lindgren0499bde2008-07-03 12:24:36 +0300604 dma_write(0, CICR(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100605}
606
607void omap_enable_dma_irq(int lch, u16 bits)
608{
609 dma_chan[lch].enabled_irqs |= bits;
610}
611
612void omap_disable_dma_irq(int lch, u16 bits)
613{
614 dma_chan[lch].enabled_irqs &= ~bits;
615}
616
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000617static inline void enable_lnk(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100618{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300619 u32 l;
620
621 l = dma_read(CLNK_CTRL(lch));
622
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000623 if (cpu_class_is_omap1())
Tony Lindgren0499bde2008-07-03 12:24:36 +0300624 l &= ~(1 << 14);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100625
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000626 /* Set the ENABLE_LNK bits */
627 if (dma_chan[lch].next_lch != -1)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300628 l = dma_chan[lch].next_lch | (1 << 15);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800629
630#ifndef CONFIG_ARCH_OMAP1
631 if (dma_chan[lch].next_linked_ch != -1)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300632 l = dma_chan[lch].next_linked_ch | (1 << 15);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800633#endif
Tony Lindgren0499bde2008-07-03 12:24:36 +0300634
635 dma_write(l, CLNK_CTRL(lch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100636}
637
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000638static inline void disable_lnk(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100639{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300640 u32 l;
641
642 l = dma_read(CLNK_CTRL(lch));
643
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000644 /* Disable interrupts */
645 if (cpu_class_is_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300646 dma_write(0, CICR(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000647 /* Set the STOP_LNK bit */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300648 l |= 1 << 14;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100649 }
650
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800651 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000652 omap_disable_channel_irq(lch);
653 /* Clear the ENABLE_LNK bit */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300654 l &= ~(1 << 15);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000655 }
656
Tony Lindgren0499bde2008-07-03 12:24:36 +0300657 dma_write(l, CLNK_CTRL(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000658 dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
659}
660
661static inline void omap2_enable_irq_lch(int lch)
662{
663 u32 val;
664
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800665 if (!cpu_class_is_omap2())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000666 return;
667
Tony Lindgren0499bde2008-07-03 12:24:36 +0300668 val = dma_read(IRQENABLE_L0);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000669 val |= 1 << lch;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300670 dma_write(val, IRQENABLE_L0);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100671}
672
673int omap_request_dma(int dev_id, const char *dev_name,
674 void (* callback)(int lch, u16 ch_status, void *data),
675 void *data, int *dma_ch_out)
676{
677 int ch, free_ch = -1;
678 unsigned long flags;
679 struct omap_dma_lch *chan;
680
681 spin_lock_irqsave(&dma_chan_lock, flags);
682 for (ch = 0; ch < dma_chan_count; ch++) {
683 if (free_ch == -1 && dma_chan[ch].dev_id == -1) {
684 free_ch = ch;
685 if (dev_id == 0)
686 break;
687 }
688 }
689 if (free_ch == -1) {
690 spin_unlock_irqrestore(&dma_chan_lock, flags);
691 return -EBUSY;
692 }
693 chan = dma_chan + free_ch;
694 chan->dev_id = dev_id;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000695
696 if (cpu_class_is_omap1())
697 clear_lch_regs(free_ch);
698
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800699 if (cpu_class_is_omap2())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000700 omap_clear_dma(free_ch);
701
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100702 spin_unlock_irqrestore(&dma_chan_lock, flags);
703
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100704 chan->dev_name = dev_name;
705 chan->callback = callback;
706 chan->data = data;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800707#ifndef CONFIG_ARCH_OMAP1
708 chan->chain_id = -1;
Jarkko Nikula0692f052008-03-17 17:01:10 +0200709 chan->next_linked_ch = -1;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800710#endif
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700711 chan->enabled_irqs = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000712
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700713 if (cpu_class_is_omap1())
714 chan->enabled_irqs |= OMAP1_DMA_TOUT_IRQ;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800715 else if (cpu_class_is_omap2())
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700716 chan->enabled_irqs |= OMAP2_DMA_MISALIGNED_ERR_IRQ |
717 OMAP2_DMA_TRANS_ERR_IRQ;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100718
719 if (cpu_is_omap16xx()) {
720 /* If the sync device is set, configure it dynamically. */
721 if (dev_id != 0) {
722 set_gdma_dev(free_ch + 1, dev_id);
723 dev_id = free_ch + 1;
724 }
725 /* Disable the 1510 compatibility mode and set the sync device
726 * id. */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300727 dma_write(dev_id | (1 << 10), CCR(free_ch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000728 } else if (cpu_is_omap730() || cpu_is_omap15xx()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300729 dma_write(dev_id, CCR(free_ch));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100730 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000731
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800732 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000733 omap2_enable_irq_lch(free_ch);
734
735 omap_enable_channel_irq(free_ch);
736 /* Clear the CSR register and IRQ status register */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300737 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(free_ch));
738 dma_write(1 << free_ch, IRQSTATUS_L0);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000739 }
740
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100741 *dma_ch_out = free_ch;
742
743 return 0;
744}
745
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000746void omap_free_dma(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100747{
748 unsigned long flags;
749
750 spin_lock_irqsave(&dma_chan_lock, flags);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000751 if (dma_chan[lch].dev_id == -1) {
752 printk("omap_dma: trying to free nonallocated DMA channel %d\n",
753 lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100754 spin_unlock_irqrestore(&dma_chan_lock, flags);
755 return;
756 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000757 dma_chan[lch].dev_id = -1;
758 dma_chan[lch].next_lch = -1;
759 dma_chan[lch].callback = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100760 spin_unlock_irqrestore(&dma_chan_lock, flags);
761
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000762 if (cpu_class_is_omap1()) {
763 /* Disable all DMA interrupts for the channel. */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300764 dma_write(0, CICR(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000765 /* Make sure the DMA transfer is stopped. */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300766 dma_write(0, CCR(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000767 }
768
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800769 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000770 u32 val;
771 /* Disable interrupts */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300772 val = dma_read(IRQENABLE_L0);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000773 val &= ~(1 << lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300774 dma_write(val, IRQENABLE_L0);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000775
776 /* Clear the CSR register and IRQ status register */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300777 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(lch));
778 dma_write(1 << lch, IRQSTATUS_L0);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000779
780 /* Disable all DMA interrupts for the channel. */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300781 dma_write(0, CICR(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000782
783 /* Make sure the DMA transfer is stopped. */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300784 dma_write(0, CCR(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000785 omap_clear_dma(lch);
786 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100787}
788
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800789/**
790 * @brief omap_dma_set_global_params : Set global priority settings for dma
791 *
792 * @param arb_rate
793 * @param max_fifo_depth
794 * @param tparams - Number of thereads to reserve : DMA_THREAD_RESERVE_NORM
795 * DMA_THREAD_RESERVE_ONET
796 * DMA_THREAD_RESERVE_TWOT
797 * DMA_THREAD_RESERVE_THREET
798 */
799void
800omap_dma_set_global_params(int arb_rate, int max_fifo_depth, int tparams)
801{
802 u32 reg;
803
804 if (!cpu_class_is_omap2()) {
Harvey Harrison8e86f422008-03-04 15:08:02 -0800805 printk(KERN_ERR "FIXME: no %s on 15xx/16xx\n", __func__);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800806 return;
807 }
808
809 if (arb_rate == 0)
810 arb_rate = 1;
811
812 reg = (arb_rate & 0xff) << 16;
813 reg |= (0xff & max_fifo_depth);
814
Tony Lindgren0499bde2008-07-03 12:24:36 +0300815 dma_write(reg, GCR);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800816}
817EXPORT_SYMBOL(omap_dma_set_global_params);
818
819/**
820 * @brief omap_dma_set_prio_lch : Set channel wise priority settings
821 *
822 * @param lch
823 * @param read_prio - Read priority
824 * @param write_prio - Write priority
825 * Both of the above can be set with one of the following values :
826 * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW
827 */
828int
829omap_dma_set_prio_lch(int lch, unsigned char read_prio,
830 unsigned char write_prio)
831{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300832 u32 l;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800833
Tony Lindgren4d963722008-07-03 12:24:31 +0300834 if (unlikely((lch < 0 || lch >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800835 printk(KERN_ERR "Invalid channel id\n");
836 return -EINVAL;
837 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300838 l = dma_read(CCR(lch));
839 l &= ~((1 << 6) | (1 << 26));
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800840 if (cpu_is_omap2430() || cpu_is_omap34xx())
Tony Lindgren0499bde2008-07-03 12:24:36 +0300841 l |= ((read_prio & 0x1) << 6) | ((write_prio & 0x1) << 26);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800842 else
Tony Lindgren0499bde2008-07-03 12:24:36 +0300843 l |= ((read_prio & 0x1) << 6);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800844
Tony Lindgren0499bde2008-07-03 12:24:36 +0300845 dma_write(l, CCR(lch));
846
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800847 return 0;
848}
849EXPORT_SYMBOL(omap_dma_set_prio_lch);
850
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000851/*
852 * Clears any DMA state so the DMA engine is ready to restart with new buffers
853 * through omap_start_dma(). Any buffers in flight are discarded.
854 */
855void omap_clear_dma(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100856{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000857 unsigned long flags;
858
859 local_irq_save(flags);
860
861 if (cpu_class_is_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300862 u32 l;
863
864 l = dma_read(CCR(lch));
865 l &= ~OMAP_DMA_CCR_EN;
866 dma_write(l, CCR(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000867
868 /* Clear pending interrupts */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300869 l = dma_read(CSR(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000870 }
871
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800872 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000873 int i;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300874 void __iomem *lch_base = omap_dma_base + OMAP_DMA4_CH_BASE(lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000875 for (i = 0; i < 0x44; i += 4)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300876 __raw_writel(0, lch_base + i);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000877 }
878
879 local_irq_restore(flags);
880}
881
882void omap_start_dma(int lch)
883{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300884 u32 l;
885
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000886 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
887 int next_lch, cur_lch;
Tony Lindgren4d963722008-07-03 12:24:31 +0300888 char dma_chan_link_map[OMAP_DMA4_LOGICAL_DMA_CH_COUNT];
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000889
890 dma_chan_link_map[lch] = 1;
891 /* Set the link register of the first channel */
892 enable_lnk(lch);
893
894 memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
895 cur_lch = dma_chan[lch].next_lch;
896 do {
897 next_lch = dma_chan[cur_lch].next_lch;
898
899 /* The loop case: we've been here already */
900 if (dma_chan_link_map[cur_lch])
901 break;
902 /* Mark the current channel */
903 dma_chan_link_map[cur_lch] = 1;
904
905 enable_lnk(cur_lch);
906 omap_enable_channel_irq(cur_lch);
907
908 cur_lch = next_lch;
909 } while (next_lch != -1);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800910 } else if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000911 /* Errata: Need to write lch even if not using chaining */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300912 dma_write(lch, CLNK_CTRL(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000913 }
914
915 omap_enable_channel_irq(lch);
916
Tony Lindgren0499bde2008-07-03 12:24:36 +0300917 l = dma_read(CCR(lch));
918
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000919 /* Errata: On ES2.0 BUFFERING disable must be set.
920 * This will always fail on ES1.0 */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300921 if (cpu_is_omap24xx())
922 l |= OMAP_DMA_CCR_EN;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000923
Tony Lindgren0499bde2008-07-03 12:24:36 +0300924 l |= OMAP_DMA_CCR_EN;
925 dma_write(l, CCR(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000926
927 dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
928}
929
930void omap_stop_dma(int lch)
931{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300932 u32 l;
933
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000934 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
935 int next_lch, cur_lch = lch;
Tony Lindgren4d963722008-07-03 12:24:31 +0300936 char dma_chan_link_map[OMAP_DMA4_LOGICAL_DMA_CH_COUNT];
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000937
938 memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
939 do {
940 /* The loop case: we've been here already */
941 if (dma_chan_link_map[cur_lch])
942 break;
943 /* Mark the current channel */
944 dma_chan_link_map[cur_lch] = 1;
945
946 disable_lnk(cur_lch);
947
948 next_lch = dma_chan[cur_lch].next_lch;
949 cur_lch = next_lch;
950 } while (next_lch != -1);
951
952 return;
953 }
954
955 /* Disable all interrupts on the channel */
956 if (cpu_class_is_omap1())
Tony Lindgren0499bde2008-07-03 12:24:36 +0300957 dma_write(0, CICR(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000958
Tony Lindgren0499bde2008-07-03 12:24:36 +0300959 l = dma_read(CCR(lch));
960 l &= ~OMAP_DMA_CCR_EN;
961 dma_write(l, CCR(lch));
962
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000963 dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
964}
965
966/*
Tony Lindgren709eb3e2006-09-25 12:45:45 +0300967 * Allows changing the DMA callback function or data. This may be needed if
968 * the driver shares a single DMA channel for multiple dma triggers.
969 */
970int omap_set_dma_callback(int lch,
971 void (* callback)(int lch, u16 ch_status, void *data),
972 void *data)
973{
974 unsigned long flags;
975
976 if (lch < 0)
977 return -ENODEV;
978
979 spin_lock_irqsave(&dma_chan_lock, flags);
980 if (dma_chan[lch].dev_id == -1) {
981 printk(KERN_ERR "DMA callback for not set for free channel\n");
982 spin_unlock_irqrestore(&dma_chan_lock, flags);
983 return -EINVAL;
984 }
985 dma_chan[lch].callback = callback;
986 dma_chan[lch].data = data;
987 spin_unlock_irqrestore(&dma_chan_lock, flags);
988
989 return 0;
990}
991
992/*
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000993 * Returns current physical source address for the given DMA channel.
994 * If the channel is running the caller must disable interrupts prior calling
995 * this function and process the returned value before re-enabling interrupt to
996 * prevent races with the interrupt handler. Note that in continuous mode there
997 * is a chance for CSSA_L register overflow inbetween the two reads resulting
998 * in incorrect return value.
999 */
1000dma_addr_t omap_get_dma_src_pos(int lch)
1001{
Tony Lindgren0695de32007-05-07 18:24:14 -07001002 dma_addr_t offset = 0;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001003
Tony Lindgren0499bde2008-07-03 12:24:36 +03001004 if (cpu_is_omap15xx())
1005 offset = dma_read(CPC(lch));
1006 else
1007 offset = dma_read(CSAC(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001008
Tony Lindgren0499bde2008-07-03 12:24:36 +03001009 /*
1010 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1011 * read before the DMA controller finished disabling the channel.
1012 */
1013 if (!cpu_is_omap15xx() && offset == 0)
1014 offset = dma_read(CSAC(lch));
1015
1016 if (cpu_class_is_omap1())
1017 offset |= (dma_read(CSSA_U(lch)) << 16);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001018
1019 return offset;
1020}
1021
1022/*
1023 * Returns current physical destination address for the given DMA channel.
1024 * If the channel is running the caller must disable interrupts prior calling
1025 * this function and process the returned value before re-enabling interrupt to
1026 * prevent races with the interrupt handler. Note that in continuous mode there
1027 * is a chance for CDSA_L register overflow inbetween the two reads resulting
1028 * in incorrect return value.
1029 */
1030dma_addr_t omap_get_dma_dst_pos(int lch)
1031{
Tony Lindgren0695de32007-05-07 18:24:14 -07001032 dma_addr_t offset = 0;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001033
Tony Lindgren0499bde2008-07-03 12:24:36 +03001034 if (cpu_is_omap15xx())
1035 offset = dma_read(CPC(lch));
1036 else
1037 offset = dma_read(CDAC(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001038
Tony Lindgren0499bde2008-07-03 12:24:36 +03001039 /*
1040 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1041 * read before the DMA controller finished disabling the channel.
1042 */
1043 if (!cpu_is_omap15xx() && offset == 0)
1044 offset = dma_read(CDAC(lch));
1045
1046 if (cpu_class_is_omap1())
1047 offset |= (dma_read(CDSA_U(lch)) << 16);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001048
1049 return offset;
1050}
1051
1052/*
1053 * Returns current source transfer counting for the given DMA channel.
1054 * Can be used to monitor the progress of a transfer inside a block.
1055 * It must be called with disabled interrupts.
1056 */
1057int omap_get_dma_src_addr_counter(int lch)
1058{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001059 return (dma_addr_t)dma_read(CSAC(lch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001060}
1061
Tony Lindgren0499bde2008-07-03 12:24:36 +03001062int omap_get_dma_active_status(int lch)
1063{
1064 return (dma_read(CCR(lch)) & OMAP_DMA_CCR_EN) != 0;
1065}
1066EXPORT_SYMBOL(omap_get_dma_active_status);
1067
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001068int omap_dma_running(void)
1069{
1070 int lch;
1071
1072 /* Check if LCD DMA is running */
1073 if (cpu_is_omap16xx())
1074 if (omap_readw(OMAP1610_DMA_LCD_CCR) & OMAP_DMA_CCR_EN)
1075 return 1;
1076
1077 for (lch = 0; lch < dma_chan_count; lch++)
Tony Lindgren0499bde2008-07-03 12:24:36 +03001078 if (dma_read(CCR(lch)) & OMAP_DMA_CCR_EN)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001079 return 1;
1080
1081 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001082}
1083
1084/*
1085 * lch_queue DMA will start right after lch_head one is finished.
1086 * For this DMA link to start, you still need to start (see omap_start_dma)
1087 * the first one. That will fire up the entire queue.
1088 */
1089void omap_dma_link_lch (int lch_head, int lch_queue)
1090{
1091 if (omap_dma_in_1510_mode()) {
1092 printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
1093 BUG();
1094 return;
1095 }
1096
1097 if ((dma_chan[lch_head].dev_id == -1) ||
1098 (dma_chan[lch_queue].dev_id == -1)) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001099 printk(KERN_ERR "omap_dma: trying to link "
1100 "non requested channels\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001101 dump_stack();
1102 }
1103
1104 dma_chan[lch_head].next_lch = lch_queue;
1105}
1106
1107/*
1108 * Once the DMA queue is stopped, we can destroy it.
1109 */
1110void omap_dma_unlink_lch (int lch_head, int lch_queue)
1111{
1112 if (omap_dma_in_1510_mode()) {
1113 printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
1114 BUG();
1115 return;
1116 }
1117
1118 if (dma_chan[lch_head].next_lch != lch_queue ||
1119 dma_chan[lch_head].next_lch == -1) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001120 printk(KERN_ERR "omap_dma: trying to unlink "
1121 "non linked channels\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001122 dump_stack();
1123 }
1124
1125
1126 if ((dma_chan[lch_head].flags & OMAP_DMA_ACTIVE) ||
1127 (dma_chan[lch_head].flags & OMAP_DMA_ACTIVE)) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001128 printk(KERN_ERR "omap_dma: You need to stop the DMA channels "
1129 "before unlinking\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001130 dump_stack();
1131 }
1132
1133 dma_chan[lch_head].next_lch = -1;
1134}
1135
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001136#ifndef CONFIG_ARCH_OMAP1
1137/* Create chain of DMA channesls */
1138static void create_dma_lch_chain(int lch_head, int lch_queue)
1139{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001140 u32 l;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001141
1142 /* Check if this is the first link in chain */
1143 if (dma_chan[lch_head].next_linked_ch == -1) {
1144 dma_chan[lch_head].next_linked_ch = lch_queue;
1145 dma_chan[lch_head].prev_linked_ch = lch_queue;
1146 dma_chan[lch_queue].next_linked_ch = lch_head;
1147 dma_chan[lch_queue].prev_linked_ch = lch_head;
1148 }
1149
1150 /* a link exists, link the new channel in circular chain */
1151 else {
1152 dma_chan[lch_queue].next_linked_ch =
1153 dma_chan[lch_head].next_linked_ch;
1154 dma_chan[lch_queue].prev_linked_ch = lch_head;
1155 dma_chan[lch_head].next_linked_ch = lch_queue;
1156 dma_chan[dma_chan[lch_queue].next_linked_ch].prev_linked_ch =
1157 lch_queue;
1158 }
1159
Tony Lindgren0499bde2008-07-03 12:24:36 +03001160 l = dma_read(CLNK_CTRL(lch_head));
1161 l &= ~(0x1f);
1162 l |= lch_queue;
1163 dma_write(l, CLNK_CTRL(lch_head));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001164
Tony Lindgren0499bde2008-07-03 12:24:36 +03001165 l = dma_read(CLNK_CTRL(lch_queue));
1166 l &= ~(0x1f);
1167 l |= (dma_chan[lch_queue].next_linked_ch);
1168 dma_write(l, CLNK_CTRL(lch_queue));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001169}
1170
1171/**
1172 * @brief omap_request_dma_chain : Request a chain of DMA channels
1173 *
1174 * @param dev_id - Device id using the dma channel
1175 * @param dev_name - Device name
1176 * @param callback - Call back function
1177 * @chain_id -
1178 * @no_of_chans - Number of channels requested
1179 * @chain_mode - Dynamic or static chaining : OMAP_DMA_STATIC_CHAIN
1180 * OMAP_DMA_DYNAMIC_CHAIN
1181 * @params - Channel parameters
1182 *
1183 * @return - Succes : 0
1184 * Failure: -EINVAL/-ENOMEM
1185 */
1186int omap_request_dma_chain(int dev_id, const char *dev_name,
1187 void (*callback) (int chain_id, u16 ch_status,
1188 void *data),
1189 int *chain_id, int no_of_chans, int chain_mode,
1190 struct omap_dma_channel_params params)
1191{
1192 int *channels;
1193 int i, err;
1194
1195 /* Is the chain mode valid ? */
1196 if (chain_mode != OMAP_DMA_STATIC_CHAIN
1197 && chain_mode != OMAP_DMA_DYNAMIC_CHAIN) {
1198 printk(KERN_ERR "Invalid chain mode requested\n");
1199 return -EINVAL;
1200 }
1201
1202 if (unlikely((no_of_chans < 1
Tony Lindgren4d963722008-07-03 12:24:31 +03001203 || no_of_chans > dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001204 printk(KERN_ERR "Invalid Number of channels requested\n");
1205 return -EINVAL;
1206 }
1207
1208 /* Allocate a queue to maintain the status of the channels
1209 * in the chain */
1210 channels = kmalloc(sizeof(*channels) * no_of_chans, GFP_KERNEL);
1211 if (channels == NULL) {
1212 printk(KERN_ERR "omap_dma: No memory for channel queue\n");
1213 return -ENOMEM;
1214 }
1215
1216 /* request and reserve DMA channels for the chain */
1217 for (i = 0; i < no_of_chans; i++) {
1218 err = omap_request_dma(dev_id, dev_name,
1219 callback, 0, &channels[i]);
1220 if (err < 0) {
1221 int j;
1222 for (j = 0; j < i; j++)
1223 omap_free_dma(channels[j]);
1224 kfree(channels);
1225 printk(KERN_ERR "omap_dma: Request failed %d\n", err);
1226 return err;
1227 }
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001228 dma_chan[channels[i]].prev_linked_ch = -1;
1229 dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
1230
1231 /*
1232 * Allowing client drivers to set common parameters now,
1233 * so that later only relevant (src_start, dest_start
1234 * and element count) can be set
1235 */
1236 omap_set_dma_params(channels[i], &params);
1237 }
1238
1239 *chain_id = channels[0];
1240 dma_linked_lch[*chain_id].linked_dmach_q = channels;
1241 dma_linked_lch[*chain_id].chain_mode = chain_mode;
1242 dma_linked_lch[*chain_id].chain_state = DMA_CHAIN_NOTSTARTED;
1243 dma_linked_lch[*chain_id].no_of_lchs_linked = no_of_chans;
1244
1245 for (i = 0; i < no_of_chans; i++)
1246 dma_chan[channels[i]].chain_id = *chain_id;
1247
1248 /* Reset the Queue pointers */
1249 OMAP_DMA_CHAIN_QINIT(*chain_id);
1250
1251 /* Set up the chain */
1252 if (no_of_chans == 1)
1253 create_dma_lch_chain(channels[0], channels[0]);
1254 else {
1255 for (i = 0; i < (no_of_chans - 1); i++)
1256 create_dma_lch_chain(channels[i], channels[i + 1]);
1257 }
1258 return 0;
1259}
1260EXPORT_SYMBOL(omap_request_dma_chain);
1261
1262/**
1263 * @brief omap_modify_dma_chain_param : Modify the chain's params - Modify the
1264 * params after setting it. Dont do this while dma is running!!
1265 *
1266 * @param chain_id - Chained logical channel id.
1267 * @param params
1268 *
1269 * @return - Success : 0
1270 * Failure : -EINVAL
1271 */
1272int omap_modify_dma_chain_params(int chain_id,
1273 struct omap_dma_channel_params params)
1274{
1275 int *channels;
1276 u32 i;
1277
1278 /* Check for input params */
1279 if (unlikely((chain_id < 0
Tony Lindgren4d963722008-07-03 12:24:31 +03001280 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001281 printk(KERN_ERR "Invalid chain id\n");
1282 return -EINVAL;
1283 }
1284
1285 /* Check if the chain exists */
1286 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1287 printk(KERN_ERR "Chain doesn't exists\n");
1288 return -EINVAL;
1289 }
1290 channels = dma_linked_lch[chain_id].linked_dmach_q;
1291
1292 for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
1293 /*
1294 * Allowing client drivers to set common parameters now,
1295 * so that later only relevant (src_start, dest_start
1296 * and element count) can be set
1297 */
1298 omap_set_dma_params(channels[i], &params);
1299 }
1300 return 0;
1301}
1302EXPORT_SYMBOL(omap_modify_dma_chain_params);
1303
1304/**
1305 * @brief omap_free_dma_chain - Free all the logical channels in a chain.
1306 *
1307 * @param chain_id
1308 *
1309 * @return - Success : 0
1310 * Failure : -EINVAL
1311 */
1312int omap_free_dma_chain(int chain_id)
1313{
1314 int *channels;
1315 u32 i;
1316
1317 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001318 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001319 printk(KERN_ERR "Invalid chain id\n");
1320 return -EINVAL;
1321 }
1322
1323 /* Check if the chain exists */
1324 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1325 printk(KERN_ERR "Chain doesn't exists\n");
1326 return -EINVAL;
1327 }
1328
1329 channels = dma_linked_lch[chain_id].linked_dmach_q;
1330 for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
1331 dma_chan[channels[i]].next_linked_ch = -1;
1332 dma_chan[channels[i]].prev_linked_ch = -1;
1333 dma_chan[channels[i]].chain_id = -1;
1334 dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
1335 omap_free_dma(channels[i]);
1336 }
1337
1338 kfree(channels);
1339
1340 dma_linked_lch[chain_id].linked_dmach_q = NULL;
1341 dma_linked_lch[chain_id].chain_mode = -1;
1342 dma_linked_lch[chain_id].chain_state = -1;
1343 return (0);
1344}
1345EXPORT_SYMBOL(omap_free_dma_chain);
1346
1347/**
1348 * @brief omap_dma_chain_status - Check if the chain is in
1349 * active / inactive state.
1350 * @param chain_id
1351 *
1352 * @return - Success : OMAP_DMA_CHAIN_ACTIVE/OMAP_DMA_CHAIN_INACTIVE
1353 * Failure : -EINVAL
1354 */
1355int omap_dma_chain_status(int chain_id)
1356{
1357 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001358 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001359 printk(KERN_ERR "Invalid chain id\n");
1360 return -EINVAL;
1361 }
1362
1363 /* Check if the chain exists */
1364 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1365 printk(KERN_ERR "Chain doesn't exists\n");
1366 return -EINVAL;
1367 }
1368 pr_debug("CHAINID=%d, qcnt=%d\n", chain_id,
1369 dma_linked_lch[chain_id].q_count);
1370
1371 if (OMAP_DMA_CHAIN_QEMPTY(chain_id))
1372 return OMAP_DMA_CHAIN_INACTIVE;
1373 return OMAP_DMA_CHAIN_ACTIVE;
1374}
1375EXPORT_SYMBOL(omap_dma_chain_status);
1376
1377/**
1378 * @brief omap_dma_chain_a_transfer - Get a free channel from a chain,
1379 * set the params and start the transfer.
1380 *
1381 * @param chain_id
1382 * @param src_start - buffer start address
1383 * @param dest_start - Dest address
1384 * @param elem_count
1385 * @param frame_count
1386 * @param callbk_data - channel callback parameter data.
1387 *
Anand Gadiyarf4b6a7e2008-03-11 01:10:35 +05301388 * @return - Success : 0
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001389 * Failure: -EINVAL/-EBUSY
1390 */
1391int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start,
1392 int elem_count, int frame_count, void *callbk_data)
1393{
1394 int *channels;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001395 u32 l, lch;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001396 int start_dma = 0;
1397
1398 /* if buffer size is less than 1 then there is
1399 * no use of starting the chain */
1400 if (elem_count < 1) {
1401 printk(KERN_ERR "Invalid buffer size\n");
1402 return -EINVAL;
1403 }
1404
1405 /* Check for input params */
1406 if (unlikely((chain_id < 0
Tony Lindgren4d963722008-07-03 12:24:31 +03001407 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001408 printk(KERN_ERR "Invalid chain id\n");
1409 return -EINVAL;
1410 }
1411
1412 /* Check if the chain exists */
1413 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1414 printk(KERN_ERR "Chain doesn't exist\n");
1415 return -EINVAL;
1416 }
1417
1418 /* Check if all the channels in chain are in use */
1419 if (OMAP_DMA_CHAIN_QFULL(chain_id))
1420 return -EBUSY;
1421
1422 /* Frame count may be negative in case of indexed transfers */
1423 channels = dma_linked_lch[chain_id].linked_dmach_q;
1424
1425 /* Get a free channel */
1426 lch = channels[dma_linked_lch[chain_id].q_tail];
1427
1428 /* Store the callback data */
1429 dma_chan[lch].data = callbk_data;
1430
1431 /* Increment the q_tail */
1432 OMAP_DMA_CHAIN_INCQTAIL(chain_id);
1433
1434 /* Set the params to the free channel */
1435 if (src_start != 0)
Tony Lindgren0499bde2008-07-03 12:24:36 +03001436 dma_write(src_start, CSSA(lch));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001437 if (dest_start != 0)
Tony Lindgren0499bde2008-07-03 12:24:36 +03001438 dma_write(dest_start, CDSA(lch));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001439
1440 /* Write the buffer size */
Tony Lindgren0499bde2008-07-03 12:24:36 +03001441 dma_write(elem_count, CEN(lch));
1442 dma_write(frame_count, CFN(lch));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001443
1444 /* If the chain is dynamically linked,
1445 * then we may have to start the chain if its not active */
1446 if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_DYNAMIC_CHAIN) {
1447
1448 /* In Dynamic chain, if the chain is not started,
1449 * queue the channel */
1450 if (dma_linked_lch[chain_id].chain_state ==
1451 DMA_CHAIN_NOTSTARTED) {
1452 /* Enable the link in previous channel */
1453 if (dma_chan[dma_chan[lch].prev_linked_ch].state ==
1454 DMA_CH_QUEUED)
1455 enable_lnk(dma_chan[lch].prev_linked_ch);
1456 dma_chan[lch].state = DMA_CH_QUEUED;
1457 }
1458
1459 /* Chain is already started, make sure its active,
1460 * if not then start the chain */
1461 else {
1462 start_dma = 1;
1463
1464 if (dma_chan[dma_chan[lch].prev_linked_ch].state ==
1465 DMA_CH_STARTED) {
1466 enable_lnk(dma_chan[lch].prev_linked_ch);
1467 dma_chan[lch].state = DMA_CH_QUEUED;
1468 start_dma = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001469 if (0 == ((1 << 7) & dma_read(
1470 CCR(dma_chan[lch].prev_linked_ch)))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001471 disable_lnk(dma_chan[lch].
1472 prev_linked_ch);
1473 pr_debug("\n prev ch is stopped\n");
1474 start_dma = 1;
1475 }
1476 }
1477
1478 else if (dma_chan[dma_chan[lch].prev_linked_ch].state
1479 == DMA_CH_QUEUED) {
1480 enable_lnk(dma_chan[lch].prev_linked_ch);
1481 dma_chan[lch].state = DMA_CH_QUEUED;
1482 start_dma = 0;
1483 }
1484 omap_enable_channel_irq(lch);
1485
Tony Lindgren0499bde2008-07-03 12:24:36 +03001486 l = dma_read(CCR(lch));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001487
Tony Lindgren0499bde2008-07-03 12:24:36 +03001488 if ((0 == (l & (1 << 24))))
1489 l &= ~(1 << 25);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001490 else
Tony Lindgren0499bde2008-07-03 12:24:36 +03001491 l |= (1 << 25);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001492 if (start_dma == 1) {
Tony Lindgren0499bde2008-07-03 12:24:36 +03001493 if (0 == (l & (1 << 7))) {
1494 l |= (1 << 7);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001495 dma_chan[lch].state = DMA_CH_STARTED;
1496 pr_debug("starting %d\n", lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001497 dma_write(l, CCR(lch));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001498 } else
1499 start_dma = 0;
1500 } else {
Tony Lindgren0499bde2008-07-03 12:24:36 +03001501 if (0 == (l & (1 << 7)))
1502 dma_write(l, CCR(lch));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001503 }
1504 dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
1505 }
1506 }
Anand Gadiyarf4b6a7e2008-03-11 01:10:35 +05301507 return 0;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001508}
1509EXPORT_SYMBOL(omap_dma_chain_a_transfer);
1510
1511/**
1512 * @brief omap_start_dma_chain_transfers - Start the chain
1513 *
1514 * @param chain_id
1515 *
1516 * @return - Success : 0
1517 * Failure : -EINVAL/-EBUSY
1518 */
1519int omap_start_dma_chain_transfers(int chain_id)
1520{
1521 int *channels;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001522 u32 l, i;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001523
Tony Lindgren4d963722008-07-03 12:24:31 +03001524 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001525 printk(KERN_ERR "Invalid chain id\n");
1526 return -EINVAL;
1527 }
1528
1529 channels = dma_linked_lch[chain_id].linked_dmach_q;
1530
1531 if (dma_linked_lch[channels[0]].chain_state == DMA_CHAIN_STARTED) {
1532 printk(KERN_ERR "Chain is already started\n");
1533 return -EBUSY;
1534 }
1535
1536 if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_STATIC_CHAIN) {
1537 for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked;
1538 i++) {
1539 enable_lnk(channels[i]);
1540 omap_enable_channel_irq(channels[i]);
1541 }
1542 } else {
1543 omap_enable_channel_irq(channels[0]);
1544 }
1545
Tony Lindgren0499bde2008-07-03 12:24:36 +03001546 l = dma_read(CCR(channels[0]));
1547 l |= (1 << 7);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001548 dma_linked_lch[chain_id].chain_state = DMA_CHAIN_STARTED;
1549 dma_chan[channels[0]].state = DMA_CH_STARTED;
1550
Tony Lindgren0499bde2008-07-03 12:24:36 +03001551 if ((0 == (l & (1 << 24))))
1552 l &= ~(1 << 25);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001553 else
Tony Lindgren0499bde2008-07-03 12:24:36 +03001554 l |= (1 << 25);
1555 dma_write(l, CCR(channels[0]));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001556
1557 dma_chan[channels[0]].flags |= OMAP_DMA_ACTIVE;
1558 return 0;
1559}
1560EXPORT_SYMBOL(omap_start_dma_chain_transfers);
1561
1562/**
1563 * @brief omap_stop_dma_chain_transfers - Stop the dma transfer of a chain.
1564 *
1565 * @param chain_id
1566 *
1567 * @return - Success : 0
1568 * Failure : EINVAL
1569 */
1570int omap_stop_dma_chain_transfers(int chain_id)
1571{
1572 int *channels;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001573 u32 l, i;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001574 u32 sys_cf;
1575
1576 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001577 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001578 printk(KERN_ERR "Invalid chain id\n");
1579 return -EINVAL;
1580 }
1581
1582 /* Check if the chain exists */
1583 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1584 printk(KERN_ERR "Chain doesn't exists\n");
1585 return -EINVAL;
1586 }
1587 channels = dma_linked_lch[chain_id].linked_dmach_q;
1588
1589 /* DMA Errata:
1590 * Special programming model needed to disable DMA before end of block
1591 */
Tony Lindgren0499bde2008-07-03 12:24:36 +03001592 sys_cf = dma_read(OCP_SYSCONFIG);
1593 l = sys_cf;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001594 /* Middle mode reg set no Standby */
Tony Lindgren0499bde2008-07-03 12:24:36 +03001595 l &= ~((1 << 12)|(1 << 13));
1596 dma_write(l, OCP_SYSCONFIG);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001597
1598 for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
1599
1600 /* Stop the Channel transmission */
Tony Lindgren0499bde2008-07-03 12:24:36 +03001601 l = dma_read(CCR(channels[i]));
1602 l &= ~(1 << 7);
1603 dma_write(l, CCR(channels[i]));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001604
1605 /* Disable the link in all the channels */
1606 disable_lnk(channels[i]);
1607 dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
1608
1609 }
1610 dma_linked_lch[chain_id].chain_state = DMA_CHAIN_NOTSTARTED;
1611
1612 /* Reset the Queue pointers */
1613 OMAP_DMA_CHAIN_QINIT(chain_id);
1614
1615 /* Errata - put in the old value */
Tony Lindgren0499bde2008-07-03 12:24:36 +03001616 dma_write(sys_cf, OCP_SYSCONFIG);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001617 return 0;
1618}
1619EXPORT_SYMBOL(omap_stop_dma_chain_transfers);
1620
1621/* Get the index of the ongoing DMA in chain */
1622/**
1623 * @brief omap_get_dma_chain_index - Get the element and frame index
1624 * of the ongoing DMA in chain
1625 *
1626 * @param chain_id
1627 * @param ei - Element index
1628 * @param fi - Frame index
1629 *
1630 * @return - Success : 0
1631 * Failure : -EINVAL
1632 */
1633int omap_get_dma_chain_index(int chain_id, int *ei, int *fi)
1634{
1635 int lch;
1636 int *channels;
1637
1638 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001639 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001640 printk(KERN_ERR "Invalid chain id\n");
1641 return -EINVAL;
1642 }
1643
1644 /* Check if the chain exists */
1645 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1646 printk(KERN_ERR "Chain doesn't exists\n");
1647 return -EINVAL;
1648 }
1649 if ((!ei) || (!fi))
1650 return -EINVAL;
1651
1652 channels = dma_linked_lch[chain_id].linked_dmach_q;
1653
1654 /* Get the current channel */
1655 lch = channels[dma_linked_lch[chain_id].q_head];
1656
Tony Lindgren0499bde2008-07-03 12:24:36 +03001657 *ei = dma_read(CCEN(lch));
1658 *fi = dma_read(CCFN(lch));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001659
1660 return 0;
1661}
1662EXPORT_SYMBOL(omap_get_dma_chain_index);
1663
1664/**
1665 * @brief omap_get_dma_chain_dst_pos - Get the destination position of the
1666 * ongoing DMA in chain
1667 *
1668 * @param chain_id
1669 *
1670 * @return - Success : Destination position
1671 * Failure : -EINVAL
1672 */
1673int omap_get_dma_chain_dst_pos(int chain_id)
1674{
1675 int lch;
1676 int *channels;
1677
1678 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001679 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001680 printk(KERN_ERR "Invalid chain id\n");
1681 return -EINVAL;
1682 }
1683
1684 /* Check if the chain exists */
1685 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1686 printk(KERN_ERR "Chain doesn't exists\n");
1687 return -EINVAL;
1688 }
1689
1690 channels = dma_linked_lch[chain_id].linked_dmach_q;
1691
1692 /* Get the current channel */
1693 lch = channels[dma_linked_lch[chain_id].q_head];
1694
Tony Lindgren0499bde2008-07-03 12:24:36 +03001695 return dma_read(CDAC(lch));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001696}
1697EXPORT_SYMBOL(omap_get_dma_chain_dst_pos);
1698
1699/**
1700 * @brief omap_get_dma_chain_src_pos - Get the source position
1701 * of the ongoing DMA in chain
1702 * @param chain_id
1703 *
1704 * @return - Success : Destination position
1705 * Failure : -EINVAL
1706 */
1707int omap_get_dma_chain_src_pos(int chain_id)
1708{
1709 int lch;
1710 int *channels;
1711
1712 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001713 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001714 printk(KERN_ERR "Invalid chain id\n");
1715 return -EINVAL;
1716 }
1717
1718 /* Check if the chain exists */
1719 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1720 printk(KERN_ERR "Chain doesn't exists\n");
1721 return -EINVAL;
1722 }
1723
1724 channels = dma_linked_lch[chain_id].linked_dmach_q;
1725
1726 /* Get the current channel */
1727 lch = channels[dma_linked_lch[chain_id].q_head];
1728
Tony Lindgren0499bde2008-07-03 12:24:36 +03001729 return dma_read(CSAC(lch));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001730}
1731EXPORT_SYMBOL(omap_get_dma_chain_src_pos);
1732#endif
1733
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001734/*----------------------------------------------------------------------------*/
1735
1736#ifdef CONFIG_ARCH_OMAP1
1737
1738static int omap1_dma_handle_ch(int ch)
1739{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001740 u32 csr;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001741
1742 if (enable_1510_mode && ch >= 6) {
1743 csr = dma_chan[ch].saved_csr;
1744 dma_chan[ch].saved_csr = 0;
1745 } else
Tony Lindgren0499bde2008-07-03 12:24:36 +03001746 csr = dma_read(CSR(ch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001747 if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) {
1748 dma_chan[ch + 6].saved_csr = csr >> 7;
1749 csr &= 0x7f;
1750 }
1751 if ((csr & 0x3f) == 0)
1752 return 0;
1753 if (unlikely(dma_chan[ch].dev_id == -1)) {
1754 printk(KERN_WARNING "Spurious interrupt from DMA channel "
1755 "%d (CSR %04x)\n", ch, csr);
1756 return 0;
1757 }
Tony Lindgren7ff879d2006-06-26 16:16:15 -07001758 if (unlikely(csr & OMAP1_DMA_TOUT_IRQ))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001759 printk(KERN_WARNING "DMA timeout with device %d\n",
1760 dma_chan[ch].dev_id);
1761 if (unlikely(csr & OMAP_DMA_DROP_IRQ))
1762 printk(KERN_WARNING "DMA synchronization event drop occurred "
1763 "with device %d\n", dma_chan[ch].dev_id);
1764 if (likely(csr & OMAP_DMA_BLOCK_IRQ))
1765 dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
1766 if (likely(dma_chan[ch].callback != NULL))
1767 dma_chan[ch].callback(ch, csr, dma_chan[ch].data);
1768 return 1;
1769}
1770
Linus Torvalds0cd61b62006-10-06 10:53:39 -07001771static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001772{
1773 int ch = ((int) dev_id) - 1;
1774 int handled = 0;
1775
1776 for (;;) {
1777 int handled_now = 0;
1778
1779 handled_now += omap1_dma_handle_ch(ch);
1780 if (enable_1510_mode && dma_chan[ch + 6].saved_csr)
1781 handled_now += omap1_dma_handle_ch(ch + 6);
1782 if (!handled_now)
1783 break;
1784 handled += handled_now;
1785 }
1786
1787 return handled ? IRQ_HANDLED : IRQ_NONE;
1788}
1789
1790#else
1791#define omap1_dma_irq_handler NULL
1792#endif
1793
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001794#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001795
1796static int omap2_dma_handle_ch(int ch)
1797{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001798 u32 status = dma_read(CSR(ch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001799
Juha Yrjola31513692006-12-06 17:13:47 -08001800 if (!status) {
1801 if (printk_ratelimit())
1802 printk(KERN_WARNING "Spurious DMA IRQ for lch %d\n", ch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001803 dma_write(1 << ch, IRQSTATUS_L0);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001804 return 0;
Juha Yrjola31513692006-12-06 17:13:47 -08001805 }
1806 if (unlikely(dma_chan[ch].dev_id == -1)) {
1807 if (printk_ratelimit())
1808 printk(KERN_WARNING "IRQ %04x for non-allocated DMA"
1809 "channel %d\n", status, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001810 return 0;
Juha Yrjola31513692006-12-06 17:13:47 -08001811 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001812 if (unlikely(status & OMAP_DMA_DROP_IRQ))
1813 printk(KERN_INFO
1814 "DMA synchronization event drop occurred with device "
1815 "%d\n", dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001816 if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ))
1817 printk(KERN_INFO "DMA transaction error with device %d\n",
1818 dma_chan[ch].dev_id);
Tony Lindgren7ff879d2006-06-26 16:16:15 -07001819 if (unlikely(status & OMAP2_DMA_SECURE_ERR_IRQ))
1820 printk(KERN_INFO "DMA secure error with device %d\n",
1821 dma_chan[ch].dev_id);
1822 if (unlikely(status & OMAP2_DMA_MISALIGNED_ERR_IRQ))
1823 printk(KERN_INFO "DMA misaligned error with device %d\n",
1824 dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001825
Tony Lindgren0499bde2008-07-03 12:24:36 +03001826 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(ch));
1827 dma_write(1 << ch, IRQSTATUS_L0);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001828
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001829 /* If the ch is not chained then chain_id will be -1 */
1830 if (dma_chan[ch].chain_id != -1) {
1831 int chain_id = dma_chan[ch].chain_id;
1832 dma_chan[ch].state = DMA_CH_NOTSTARTED;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001833 if (dma_read(CLNK_CTRL(ch)) & (1 << 15))
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001834 dma_chan[dma_chan[ch].next_linked_ch].state =
1835 DMA_CH_STARTED;
1836 if (dma_linked_lch[chain_id].chain_mode ==
1837 OMAP_DMA_DYNAMIC_CHAIN)
1838 disable_lnk(ch);
1839
1840 if (!OMAP_DMA_CHAIN_QEMPTY(chain_id))
1841 OMAP_DMA_CHAIN_INCQHEAD(chain_id);
1842
Tony Lindgren0499bde2008-07-03 12:24:36 +03001843 status = dma_read(CSR(ch));
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001844 }
1845
Jarkko Nikula538528d2008-02-13 11:47:29 +02001846 if (likely(dma_chan[ch].callback != NULL))
1847 dma_chan[ch].callback(ch, status, dma_chan[ch].data);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001848
Tony Lindgren0499bde2008-07-03 12:24:36 +03001849 dma_write(status, CSR(ch));
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001850
1851 return 0;
1852}
1853
1854/* STATUS register count is from 1-32 while our is 0-31 */
Linus Torvalds0cd61b62006-10-06 10:53:39 -07001855static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001856{
1857 u32 val;
1858 int i;
1859
Tony Lindgren0499bde2008-07-03 12:24:36 +03001860 val = dma_read(IRQSTATUS_L0);
Juha Yrjola31513692006-12-06 17:13:47 -08001861 if (val == 0) {
1862 if (printk_ratelimit())
1863 printk(KERN_WARNING "Spurious DMA IRQ\n");
1864 return IRQ_HANDLED;
1865 }
Tony Lindgren4d963722008-07-03 12:24:31 +03001866 for (i = 0; i < dma_lch_count && val != 0; i++) {
Juha Yrjola31513692006-12-06 17:13:47 -08001867 if (val & 1)
1868 omap2_dma_handle_ch(i);
1869 val >>= 1;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001870 }
1871
1872 return IRQ_HANDLED;
1873}
1874
1875static struct irqaction omap24xx_dma_irq = {
1876 .name = "DMA",
1877 .handler = omap2_dma_irq_handler,
Thomas Gleixner52e405e2006-07-03 02:20:05 +02001878 .flags = IRQF_DISABLED
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001879};
1880
1881#else
1882static struct irqaction omap24xx_dma_irq;
1883#endif
1884
1885/*----------------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001886
1887static struct lcd_dma_info {
1888 spinlock_t lock;
1889 int reserved;
1890 void (* callback)(u16 status, void *data);
1891 void *cb_data;
1892
1893 int active;
1894 unsigned long addr, size;
1895 int rotate, data_type, xres, yres;
1896 int vxres;
1897 int mirror;
1898 int xscale, yscale;
1899 int ext_ctrl;
1900 int src_port;
1901 int single_transfer;
1902} lcd_dma;
1903
1904void omap_set_lcd_dma_b1(unsigned long addr, u16 fb_xres, u16 fb_yres,
1905 int data_type)
1906{
1907 lcd_dma.addr = addr;
1908 lcd_dma.data_type = data_type;
1909 lcd_dma.xres = fb_xres;
1910 lcd_dma.yres = fb_yres;
1911}
1912
1913void omap_set_lcd_dma_src_port(int port)
1914{
1915 lcd_dma.src_port = port;
1916}
1917
1918void omap_set_lcd_dma_ext_controller(int external)
1919{
1920 lcd_dma.ext_ctrl = external;
1921}
1922
1923void omap_set_lcd_dma_single_transfer(int single)
1924{
1925 lcd_dma.single_transfer = single;
1926}
1927
1928
1929void omap_set_lcd_dma_b1_rotation(int rotate)
1930{
1931 if (omap_dma_in_1510_mode()) {
1932 printk(KERN_ERR "DMA rotation is not supported in 1510 mode\n");
1933 BUG();
1934 return;
1935 }
1936 lcd_dma.rotate = rotate;
1937}
1938
1939void omap_set_lcd_dma_b1_mirror(int mirror)
1940{
1941 if (omap_dma_in_1510_mode()) {
1942 printk(KERN_ERR "DMA mirror is not supported in 1510 mode\n");
1943 BUG();
1944 }
1945 lcd_dma.mirror = mirror;
1946}
1947
1948void omap_set_lcd_dma_b1_vxres(unsigned long vxres)
1949{
1950 if (omap_dma_in_1510_mode()) {
1951 printk(KERN_ERR "DMA virtual resulotion is not supported "
1952 "in 1510 mode\n");
1953 BUG();
1954 }
1955 lcd_dma.vxres = vxres;
1956}
1957
1958void omap_set_lcd_dma_b1_scale(unsigned int xscale, unsigned int yscale)
1959{
1960 if (omap_dma_in_1510_mode()) {
1961 printk(KERN_ERR "DMA scale is not supported in 1510 mode\n");
1962 BUG();
1963 }
1964 lcd_dma.xscale = xscale;
1965 lcd_dma.yscale = yscale;
1966}
1967
1968static void set_b1_regs(void)
1969{
1970 unsigned long top, bottom;
1971 int es;
1972 u16 w;
1973 unsigned long en, fn;
1974 long ei, fi;
1975 unsigned long vxres;
1976 unsigned int xscale, yscale;
1977
1978 switch (lcd_dma.data_type) {
1979 case OMAP_DMA_DATA_TYPE_S8:
1980 es = 1;
1981 break;
1982 case OMAP_DMA_DATA_TYPE_S16:
1983 es = 2;
1984 break;
1985 case OMAP_DMA_DATA_TYPE_S32:
1986 es = 4;
1987 break;
1988 default:
1989 BUG();
1990 return;
1991 }
1992
1993 vxres = lcd_dma.vxres ? lcd_dma.vxres : lcd_dma.xres;
1994 xscale = lcd_dma.xscale ? lcd_dma.xscale : 1;
1995 yscale = lcd_dma.yscale ? lcd_dma.yscale : 1;
1996 BUG_ON(vxres < lcd_dma.xres);
1997#define PIXADDR(x,y) (lcd_dma.addr + ((y) * vxres * yscale + (x) * xscale) * es)
1998#define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
1999 switch (lcd_dma.rotate) {
2000 case 0:
2001 if (!lcd_dma.mirror) {
2002 top = PIXADDR(0, 0);
2003 bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
2004 /* 1510 DMA requires the bottom address to be 2 more
2005 * than the actual last memory access location. */
2006 if (omap_dma_in_1510_mode() &&
2007 lcd_dma.data_type == OMAP_DMA_DATA_TYPE_S32)
2008 bottom += 2;
2009 ei = PIXSTEP(0, 0, 1, 0);
2010 fi = PIXSTEP(lcd_dma.xres - 1, 0, 0, 1);
2011 } else {
2012 top = PIXADDR(lcd_dma.xres - 1, 0);
2013 bottom = PIXADDR(0, lcd_dma.yres - 1);
2014 ei = PIXSTEP(1, 0, 0, 0);
2015 fi = PIXSTEP(0, 0, lcd_dma.xres - 1, 1);
2016 }
2017 en = lcd_dma.xres;
2018 fn = lcd_dma.yres;
2019 break;
2020 case 90:
2021 if (!lcd_dma.mirror) {
2022 top = PIXADDR(0, lcd_dma.yres - 1);
2023 bottom = PIXADDR(lcd_dma.xres - 1, 0);
2024 ei = PIXSTEP(0, 1, 0, 0);
2025 fi = PIXSTEP(0, 0, 1, lcd_dma.yres - 1);
2026 } else {
2027 top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
2028 bottom = PIXADDR(0, 0);
2029 ei = PIXSTEP(0, 1, 0, 0);
2030 fi = PIXSTEP(1, 0, 0, lcd_dma.yres - 1);
2031 }
2032 en = lcd_dma.yres;
2033 fn = lcd_dma.xres;
2034 break;
2035 case 180:
2036 if (!lcd_dma.mirror) {
2037 top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
2038 bottom = PIXADDR(0, 0);
2039 ei = PIXSTEP(1, 0, 0, 0);
2040 fi = PIXSTEP(0, 1, lcd_dma.xres - 1, 0);
2041 } else {
2042 top = PIXADDR(0, lcd_dma.yres - 1);
2043 bottom = PIXADDR(lcd_dma.xres - 1, 0);
2044 ei = PIXSTEP(0, 0, 1, 0);
2045 fi = PIXSTEP(lcd_dma.xres - 1, 1, 0, 0);
2046 }
2047 en = lcd_dma.xres;
2048 fn = lcd_dma.yres;
2049 break;
2050 case 270:
2051 if (!lcd_dma.mirror) {
2052 top = PIXADDR(lcd_dma.xres - 1, 0);
2053 bottom = PIXADDR(0, lcd_dma.yres - 1);
2054 ei = PIXSTEP(0, 0, 0, 1);
2055 fi = PIXSTEP(1, lcd_dma.yres - 1, 0, 0);
2056 } else {
2057 top = PIXADDR(0, 0);
2058 bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
2059 ei = PIXSTEP(0, 0, 0, 1);
2060 fi = PIXSTEP(0, lcd_dma.yres - 1, 1, 0);
2061 }
2062 en = lcd_dma.yres;
2063 fn = lcd_dma.xres;
2064 break;
2065 default:
2066 BUG();
Simon Arlott6cbdc8c2007-05-11 20:40:30 +01002067 return; /* Suppress warning about uninitialized vars */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002068 }
2069
2070 if (omap_dma_in_1510_mode()) {
2071 omap_writew(top >> 16, OMAP1510_DMA_LCD_TOP_F1_U);
2072 omap_writew(top, OMAP1510_DMA_LCD_TOP_F1_L);
2073 omap_writew(bottom >> 16, OMAP1510_DMA_LCD_BOT_F1_U);
2074 omap_writew(bottom, OMAP1510_DMA_LCD_BOT_F1_L);
2075
2076 return;
2077 }
2078
2079 /* 1610 regs */
2080 omap_writew(top >> 16, OMAP1610_DMA_LCD_TOP_B1_U);
2081 omap_writew(top, OMAP1610_DMA_LCD_TOP_B1_L);
2082 omap_writew(bottom >> 16, OMAP1610_DMA_LCD_BOT_B1_U);
2083 omap_writew(bottom, OMAP1610_DMA_LCD_BOT_B1_L);
2084
2085 omap_writew(en, OMAP1610_DMA_LCD_SRC_EN_B1);
2086 omap_writew(fn, OMAP1610_DMA_LCD_SRC_FN_B1);
2087
2088 w = omap_readw(OMAP1610_DMA_LCD_CSDP);
2089 w &= ~0x03;
2090 w |= lcd_dma.data_type;
2091 omap_writew(w, OMAP1610_DMA_LCD_CSDP);
2092
2093 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
2094 /* Always set the source port as SDRAM for now*/
2095 w &= ~(0x03 << 6);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002096 if (lcd_dma.callback != NULL)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002097 w |= 1 << 1; /* Block interrupt enable */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002098 else
2099 w &= ~(1 << 1);
2100 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
2101
2102 if (!(lcd_dma.rotate || lcd_dma.mirror ||
2103 lcd_dma.vxres || lcd_dma.xscale || lcd_dma.yscale))
2104 return;
2105
2106 w = omap_readw(OMAP1610_DMA_LCD_CCR);
2107 /* Set the double-indexed addressing mode */
2108 w |= (0x03 << 12);
2109 omap_writew(w, OMAP1610_DMA_LCD_CCR);
2110
2111 omap_writew(ei, OMAP1610_DMA_LCD_SRC_EI_B1);
2112 omap_writew(fi >> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U);
2113 omap_writew(fi, OMAP1610_DMA_LCD_SRC_FI_B1_L);
2114}
2115
Linus Torvalds0cd61b62006-10-06 10:53:39 -07002116static irqreturn_t lcd_dma_irq_handler(int irq, void *dev_id)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002117{
2118 u16 w;
2119
2120 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
2121 if (unlikely(!(w & (1 << 3)))) {
2122 printk(KERN_WARNING "Spurious LCD DMA IRQ\n");
2123 return IRQ_NONE;
2124 }
2125 /* Ack the IRQ */
2126 w |= (1 << 3);
2127 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
2128 lcd_dma.active = 0;
2129 if (lcd_dma.callback != NULL)
2130 lcd_dma.callback(w, lcd_dma.cb_data);
2131
2132 return IRQ_HANDLED;
2133}
2134
2135int omap_request_lcd_dma(void (* callback)(u16 status, void *data),
2136 void *data)
2137{
2138 spin_lock_irq(&lcd_dma.lock);
2139 if (lcd_dma.reserved) {
2140 spin_unlock_irq(&lcd_dma.lock);
2141 printk(KERN_ERR "LCD DMA channel already reserved\n");
2142 BUG();
2143 return -EBUSY;
2144 }
2145 lcd_dma.reserved = 1;
2146 spin_unlock_irq(&lcd_dma.lock);
2147 lcd_dma.callback = callback;
2148 lcd_dma.cb_data = data;
2149 lcd_dma.active = 0;
2150 lcd_dma.single_transfer = 0;
2151 lcd_dma.rotate = 0;
2152 lcd_dma.vxres = 0;
2153 lcd_dma.mirror = 0;
2154 lcd_dma.xscale = 0;
2155 lcd_dma.yscale = 0;
2156 lcd_dma.ext_ctrl = 0;
2157 lcd_dma.src_port = 0;
2158
2159 return 0;
2160}
2161
2162void omap_free_lcd_dma(void)
2163{
2164 spin_lock(&lcd_dma.lock);
2165 if (!lcd_dma.reserved) {
2166 spin_unlock(&lcd_dma.lock);
2167 printk(KERN_ERR "LCD DMA is not reserved\n");
2168 BUG();
2169 return;
2170 }
2171 if (!enable_1510_mode)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002172 omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR) & ~1,
2173 OMAP1610_DMA_LCD_CCR);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002174 lcd_dma.reserved = 0;
2175 spin_unlock(&lcd_dma.lock);
2176}
2177
2178void omap_enable_lcd_dma(void)
2179{
2180 u16 w;
2181
2182 /* Set the Enable bit only if an external controller is
2183 * connected. Otherwise the OMAP internal controller will
2184 * start the transfer when it gets enabled.
2185 */
2186 if (enable_1510_mode || !lcd_dma.ext_ctrl)
2187 return;
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01002188
2189 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
2190 w |= 1 << 8;
2191 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
2192
Tony Lindgren92105bb2005-09-07 17:20:26 +01002193 lcd_dma.active = 1;
2194
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002195 w = omap_readw(OMAP1610_DMA_LCD_CCR);
2196 w |= 1 << 7;
2197 omap_writew(w, OMAP1610_DMA_LCD_CCR);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002198}
2199
2200void omap_setup_lcd_dma(void)
2201{
2202 BUG_ON(lcd_dma.active);
2203 if (!enable_1510_mode) {
2204 /* Set some reasonable defaults */
2205 omap_writew(0x5440, OMAP1610_DMA_LCD_CCR);
2206 omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP);
2207 omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL);
2208 }
2209 set_b1_regs();
2210 if (!enable_1510_mode) {
2211 u16 w;
2212
2213 w = omap_readw(OMAP1610_DMA_LCD_CCR);
2214 /* If DMA was already active set the end_prog bit to have
2215 * the programmed register set loaded into the active
2216 * register set.
2217 */
2218 w |= 1 << 11; /* End_prog */
2219 if (!lcd_dma.single_transfer)
2220 w |= (3 << 8); /* Auto_init, repeat */
2221 omap_writew(w, OMAP1610_DMA_LCD_CCR);
2222 }
2223}
2224
2225void omap_stop_lcd_dma(void)
2226{
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01002227 u16 w;
2228
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002229 lcd_dma.active = 0;
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01002230 if (enable_1510_mode || !lcd_dma.ext_ctrl)
2231 return;
2232
2233 w = omap_readw(OMAP1610_DMA_LCD_CCR);
2234 w &= ~(1 << 7);
2235 omap_writew(w, OMAP1610_DMA_LCD_CCR);
2236
2237 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
2238 w &= ~(1 << 8);
2239 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002240}
2241
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002242/*----------------------------------------------------------------------------*/
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01002243
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002244static int __init omap_init_dma(void)
2245{
2246 int ch, r;
2247
Tony Lindgren0499bde2008-07-03 12:24:36 +03002248 if (cpu_class_is_omap1()) {
2249 omap_dma_base = (void __iomem *)IO_ADDRESS(OMAP1_DMA_BASE);
Tony Lindgren4d963722008-07-03 12:24:31 +03002250 dma_lch_count = OMAP1_LOGICAL_DMA_CH_COUNT;
Tony Lindgren0499bde2008-07-03 12:24:36 +03002251 } else if (cpu_is_omap24xx()) {
2252 omap_dma_base = (void __iomem *)IO_ADDRESS(OMAP24XX_DMA4_BASE);
Tony Lindgren4d963722008-07-03 12:24:31 +03002253 dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
Tony Lindgren0499bde2008-07-03 12:24:36 +03002254 } else if (cpu_is_omap34xx()) {
2255 omap_dma_base = (void __iomem *)IO_ADDRESS(OMAP34XX_DMA4_BASE);
2256 dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
2257 } else {
2258 pr_err("DMA init failed for unsupported omap\n");
2259 return -ENODEV;
2260 }
Tony Lindgren4d963722008-07-03 12:24:31 +03002261
2262 dma_chan = kzalloc(sizeof(struct omap_dma_lch) * dma_lch_count,
2263 GFP_KERNEL);
2264 if (!dma_chan)
2265 return -ENOMEM;
2266
2267 if (cpu_class_is_omap2()) {
2268 dma_linked_lch = kzalloc(sizeof(struct dma_link_info) *
2269 dma_lch_count, GFP_KERNEL);
2270 if (!dma_linked_lch) {
2271 kfree(dma_chan);
2272 return -ENOMEM;
2273 }
2274 }
2275
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002276 if (cpu_is_omap15xx()) {
2277 printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002278 dma_chan_count = 9;
2279 enable_1510_mode = 1;
2280 } else if (cpu_is_omap16xx() || cpu_is_omap730()) {
2281 printk(KERN_INFO "OMAP DMA hardware version %d\n",
Tony Lindgren0499bde2008-07-03 12:24:36 +03002282 dma_read(HW_ID));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002283 printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
Tony Lindgren0499bde2008-07-03 12:24:36 +03002284 (dma_read(CAPS_0_U) << 16) |
2285 dma_read(CAPS_0_L),
2286 (dma_read(CAPS_1_U) << 16) |
2287 dma_read(CAPS_1_L),
2288 dma_read(CAPS_2), dma_read(CAPS_3),
2289 dma_read(CAPS_4));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002290 if (!enable_1510_mode) {
2291 u16 w;
2292
2293 /* Disable OMAP 3.0/3.1 compatibility mode. */
Tony Lindgren0499bde2008-07-03 12:24:36 +03002294 w = dma_read(GSCR);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002295 w |= 1 << 3;
Tony Lindgren0499bde2008-07-03 12:24:36 +03002296 dma_write(w, GSCR);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002297 dma_chan_count = 16;
2298 } else
2299 dma_chan_count = 9;
Imre Deakb5beef52006-09-25 12:41:28 +03002300 if (cpu_is_omap16xx()) {
2301 u16 w;
2302
2303 /* this would prevent OMAP sleep */
2304 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
2305 w &= ~(1 << 8);
2306 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
2307 }
Anand Gadiyarf8151e52007-12-01 12:14:11 -08002308 } else if (cpu_class_is_omap2()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +03002309 u8 revision = dma_read(REVISION) & 0xff;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002310 printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
2311 revision >> 4, revision & 0xf);
Tony Lindgren4d963722008-07-03 12:24:31 +03002312 dma_chan_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002313 } else {
2314 dma_chan_count = 0;
2315 return 0;
2316 }
2317
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002318 spin_lock_init(&lcd_dma.lock);
2319 spin_lock_init(&dma_chan_lock);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002320
2321 for (ch = 0; ch < dma_chan_count; ch++) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002322 omap_clear_dma(ch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002323 dma_chan[ch].dev_id = -1;
2324 dma_chan[ch].next_lch = -1;
2325
2326 if (ch >= 6 && enable_1510_mode)
2327 continue;
2328
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002329 if (cpu_class_is_omap1()) {
2330 /* request_irq() doesn't like dev_id (ie. ch) being
2331 * zero, so we have to kludge around this. */
2332 r = request_irq(omap1_dma_irq[ch],
2333 omap1_dma_irq_handler, 0, "DMA",
2334 (void *) (ch + 1));
2335 if (r != 0) {
2336 int i;
2337
2338 printk(KERN_ERR "unable to request IRQ %d "
2339 "for DMA (error %d)\n",
2340 omap1_dma_irq[ch], r);
2341 for (i = 0; i < ch; i++)
2342 free_irq(omap1_dma_irq[i],
2343 (void *) (i + 1));
2344 return r;
2345 }
2346 }
2347 }
2348
Anand Gadiyarf8151e52007-12-01 12:14:11 -08002349 if (cpu_is_omap2430() || cpu_is_omap34xx())
2350 omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE,
2351 DMA_DEFAULT_FIFO_DEPTH, 0);
2352
2353 if (cpu_class_is_omap2())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002354 setup_irq(INT_24XX_SDMA_IRQ0, &omap24xx_dma_irq);
2355
2356 /* FIXME: Update LCD DMA to work on 24xx */
2357 if (cpu_class_is_omap1()) {
2358 r = request_irq(INT_DMA_LCD, lcd_dma_irq_handler, 0,
2359 "LCD DMA", NULL);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002360 if (r != 0) {
2361 int i;
2362
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002363 printk(KERN_ERR "unable to request IRQ for LCD DMA "
2364 "(error %d)\n", r);
2365 for (i = 0; i < dma_chan_count; i++)
2366 free_irq(omap1_dma_irq[i], (void *) (i + 1));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002367 return r;
2368 }
2369 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002370
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002371 return 0;
2372}
2373
2374arch_initcall(omap_init_dma);
2375
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002376EXPORT_SYMBOL(omap_get_dma_src_pos);
2377EXPORT_SYMBOL(omap_get_dma_dst_pos);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002378EXPORT_SYMBOL(omap_get_dma_src_addr_counter);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002379EXPORT_SYMBOL(omap_clear_dma);
2380EXPORT_SYMBOL(omap_set_dma_priority);
2381EXPORT_SYMBOL(omap_request_dma);
2382EXPORT_SYMBOL(omap_free_dma);
2383EXPORT_SYMBOL(omap_start_dma);
2384EXPORT_SYMBOL(omap_stop_dma);
Tony Lindgren123e9a52006-09-25 12:41:34 +03002385EXPORT_SYMBOL(omap_set_dma_callback);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002386EXPORT_SYMBOL(omap_enable_dma_irq);
2387EXPORT_SYMBOL(omap_disable_dma_irq);
2388
2389EXPORT_SYMBOL(omap_set_dma_transfer_params);
2390EXPORT_SYMBOL(omap_set_dma_color_mode);
Tony Lindgren123e9a52006-09-25 12:41:34 +03002391EXPORT_SYMBOL(omap_set_dma_write_mode);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002392
2393EXPORT_SYMBOL(omap_set_dma_src_params);
2394EXPORT_SYMBOL(omap_set_dma_src_index);
2395EXPORT_SYMBOL(omap_set_dma_src_data_pack);
2396EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
2397
2398EXPORT_SYMBOL(omap_set_dma_dest_params);
2399EXPORT_SYMBOL(omap_set_dma_dest_index);
2400EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
2401EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
2402
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002403EXPORT_SYMBOL(omap_set_dma_params);
2404
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002405EXPORT_SYMBOL(omap_dma_link_lch);
2406EXPORT_SYMBOL(omap_dma_unlink_lch);
2407
2408EXPORT_SYMBOL(omap_request_lcd_dma);
2409EXPORT_SYMBOL(omap_free_lcd_dma);
2410EXPORT_SYMBOL(omap_enable_lcd_dma);
2411EXPORT_SYMBOL(omap_setup_lcd_dma);
2412EXPORT_SYMBOL(omap_stop_lcd_dma);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002413EXPORT_SYMBOL(omap_set_lcd_dma_b1);
2414EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer);
2415EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller);
2416EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation);
2417EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres);
2418EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale);
2419EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror);
2420