blob: 49a7cd4763f97a0b8b299e4b7a8d9cfa96618c1e [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
2 * linux/arch/arm/plat-omap/dma.c
3 *
Tony Lindgren97b7f712008-07-03 12:24:37 +03004 * Copyright (C) 2003 - 2008 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 *
Santosh Shilimkar44169072009-05-28 14:16:04 -070013 * Copyright (C) 2009 Texas Instruments
14 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
15 *
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010016 * Support functions for the OMAP internal DMA channels.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License version 2 as
20 * published by the Free Software Foundation.
21 *
22 */
23
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/sched.h>
27#include <linux/spinlock.h>
28#include <linux/errno.h>
29#include <linux/interrupt.h>
Thomas Gleixner418ca1f2006-07-01 22:32:41 +010030#include <linux/irq.h>
Tony Lindgren97b7f712008-07-03 12:24:37 +030031#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -070033#include <linux/delay.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010034
35#include <asm/system.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010036#include <mach/hardware.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070037#include <plat/dma.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010038
Tony Lindgrence491cf2009-10-20 09:40:47 -070039#include <plat/tc.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010040
Anand Gadiyarf8151e52007-12-01 12:14:11 -080041#undef DEBUG
42
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -080043static u16 reg_map_omap1[] = {
44 [GCR] = 0x400,
45 [GSCR] = 0x404,
46 [GRST1] = 0x408,
47 [HW_ID] = 0x442,
48 [PCH2_ID] = 0x444,
49 [PCH0_ID] = 0x446,
50 [PCH1_ID] = 0x448,
51 [PCHG_ID] = 0x44a,
52 [PCHD_ID] = 0x44c,
53 [CAPS_0] = 0x44e,
54 [CAPS_1] = 0x452,
55 [CAPS_2] = 0x456,
56 [CAPS_3] = 0x458,
57 [CAPS_4] = 0x45a,
58 [PCH2_SR] = 0x460,
59 [PCH0_SR] = 0x480,
60 [PCH1_SR] = 0x482,
61 [PCHD_SR] = 0x4c0,
62
63 /* Common Registers */
64 [CSDP] = 0x00,
65 [CCR] = 0x02,
66 [CICR] = 0x04,
67 [CSR] = 0x06,
68 [CEN] = 0x10,
69 [CFN] = 0x12,
70 [CSFI] = 0x14,
71 [CSEI] = 0x16,
72 [CPC] = 0x18, /* 15xx only */
73 [CSAC] = 0x18,
74 [CDAC] = 0x1a,
75 [CDEI] = 0x1c,
76 [CDFI] = 0x1e,
77 [CLNK_CTRL] = 0x28,
78
79 /* Channel specific register offsets */
80 [CSSA] = 0x08,
81 [CDSA] = 0x0c,
82 [COLOR] = 0x20,
83 [CCR2] = 0x24,
84 [LCH_CTRL] = 0x2a,
85};
86
87static u16 reg_map_omap2[] = {
88 [REVISION] = 0x00,
89 [GCR] = 0x78,
90 [IRQSTATUS_L0] = 0x08,
91 [IRQSTATUS_L1] = 0x0c,
92 [IRQSTATUS_L2] = 0x10,
93 [IRQSTATUS_L3] = 0x14,
94 [IRQENABLE_L0] = 0x18,
95 [IRQENABLE_L1] = 0x1c,
96 [IRQENABLE_L2] = 0x20,
97 [IRQENABLE_L3] = 0x24,
98 [SYSSTATUS] = 0x28,
99 [OCP_SYSCONFIG] = 0x2c,
100 [CAPS_0] = 0x64,
101 [CAPS_2] = 0x6c,
102 [CAPS_3] = 0x70,
103 [CAPS_4] = 0x74,
104
105 /* Common register offsets */
106 [CCR] = 0x80,
107 [CLNK_CTRL] = 0x84,
108 [CICR] = 0x88,
109 [CSR] = 0x8c,
110 [CSDP] = 0x90,
111 [CEN] = 0x94,
112 [CFN] = 0x98,
113 [CSEI] = 0xa4,
114 [CSFI] = 0xa8,
115 [CDEI] = 0xac,
116 [CDFI] = 0xb0,
117 [CSAC] = 0xb4,
118 [CDAC] = 0xb8,
119
120 /* Channel specific register offsets */
121 [CSSA] = 0x9c,
122 [CDSA] = 0xa0,
123 [CCEN] = 0xbc,
124 [CCFN] = 0xc0,
125 [COLOR] = 0xc4,
126
127 /* OMAP4 specific registers */
128 [CDP] = 0xd0,
129 [CNDP] = 0xd4,
130 [CCDN] = 0xd8,
131};
132
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800133#ifndef CONFIG_ARCH_OMAP1
134enum { DMA_CH_ALLOC_DONE, DMA_CH_PARAMS_SET_DONE, DMA_CH_STARTED,
135 DMA_CH_QUEUED, DMA_CH_NOTSTARTED, DMA_CH_PAUSED, DMA_CH_LINK_ENABLED
136};
137
138enum { DMA_CHAIN_STARTED, DMA_CHAIN_NOTSTARTED };
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000139#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100140
Tony Lindgren97b7f712008-07-03 12:24:37 +0300141#define OMAP_DMA_ACTIVE 0x01
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700142#define OMAP2_DMA_CSR_CLEAR_MASK 0xffe
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100143
Tony Lindgren97b7f712008-07-03 12:24:37 +0300144#define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100145
Tony Lindgren97b7f712008-07-03 12:24:37 +0300146static int enable_1510_mode;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100147
Tero Kristof2d11852008-08-28 13:13:31 +0000148static struct omap_dma_global_context_registers {
149 u32 dma_irqenable_l0;
150 u32 dma_ocp_sysconfig;
151 u32 dma_gcr;
152} omap_dma_global_context;
153
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100154struct omap_dma_lch {
155 int next_lch;
156 int dev_id;
157 u16 saved_csr;
158 u16 enabled_irqs;
159 const char *dev_name;
Tony Lindgren97b7f712008-07-03 12:24:37 +0300160 void (*callback)(int lch, u16 ch_status, void *data);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100161 void *data;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800162
163#ifndef CONFIG_ARCH_OMAP1
164 /* required for Dynamic chaining */
165 int prev_linked_ch;
166 int next_linked_ch;
167 int state;
168 int chain_id;
169
170 int status;
171#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100172 long flags;
173};
174
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800175struct dma_link_info {
176 int *linked_dmach_q;
177 int no_of_lchs_linked;
178
179 int q_count;
180 int q_tail;
181 int q_head;
182
183 int chain_state;
184 int chain_mode;
185
186};
187
Tony Lindgren4d963722008-07-03 12:24:31 +0300188static struct dma_link_info *dma_linked_lch;
189
190#ifndef CONFIG_ARCH_OMAP1
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800191
192/* Chain handling macros */
193#define OMAP_DMA_CHAIN_QINIT(chain_id) \
194 do { \
195 dma_linked_lch[chain_id].q_head = \
196 dma_linked_lch[chain_id].q_tail = \
197 dma_linked_lch[chain_id].q_count = 0; \
198 } while (0)
199#define OMAP_DMA_CHAIN_QFULL(chain_id) \
200 (dma_linked_lch[chain_id].no_of_lchs_linked == \
201 dma_linked_lch[chain_id].q_count)
202#define OMAP_DMA_CHAIN_QLAST(chain_id) \
203 do { \
204 ((dma_linked_lch[chain_id].no_of_lchs_linked-1) == \
205 dma_linked_lch[chain_id].q_count) \
206 } while (0)
207#define OMAP_DMA_CHAIN_QEMPTY(chain_id) \
208 (0 == dma_linked_lch[chain_id].q_count)
209#define __OMAP_DMA_CHAIN_INCQ(end) \
210 ((end) = ((end)+1) % dma_linked_lch[chain_id].no_of_lchs_linked)
211#define OMAP_DMA_CHAIN_INCQHEAD(chain_id) \
212 do { \
213 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_head); \
214 dma_linked_lch[chain_id].q_count--; \
215 } while (0)
216
217#define OMAP_DMA_CHAIN_INCQTAIL(chain_id) \
218 do { \
219 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_tail); \
220 dma_linked_lch[chain_id].q_count++; \
221 } while (0)
222#endif
Tony Lindgren4d963722008-07-03 12:24:31 +0300223
224static int dma_lch_count;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100225static int dma_chan_count;
Santosh Shilimkar2263f022009-03-23 18:07:48 -0700226static int omap_dma_reserve_channels;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100227
228static spinlock_t dma_chan_lock;
Tony Lindgren4d963722008-07-03 12:24:31 +0300229static struct omap_dma_lch *dma_chan;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300230static void __iomem *omap_dma_base;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800231static u16 *reg_map;
232static u8 dma_stride;
233static enum omap_reg_offsets dma_common_ch_start, dma_common_ch_end;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100234
Tony Lindgren4d963722008-07-03 12:24:31 +0300235static const u8 omap1_dma_irq[OMAP1_LOGICAL_DMA_CH_COUNT] = {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100236 INT_DMA_CH0_6, INT_DMA_CH1_7, INT_DMA_CH2_8, INT_DMA_CH3,
237 INT_DMA_CH4, INT_DMA_CH5, INT_1610_DMA_CH6, INT_1610_DMA_CH7,
238 INT_1610_DMA_CH8, INT_1610_DMA_CH9, INT_1610_DMA_CH10,
239 INT_1610_DMA_CH11, INT_1610_DMA_CH12, INT_1610_DMA_CH13,
240 INT_1610_DMA_CH14, INT_1610_DMA_CH15, INT_DMA_LCD
241};
242
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800243static inline void disable_lnk(int lch);
244static void omap_disable_channel_irq(int lch);
245static inline void omap_enable_channel_irq(int lch);
246
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000247#define REVISIT_24XX() printk(KERN_ERR "FIXME: no %s on 24xx\n", \
Harvey Harrison8e86f422008-03-04 15:08:02 -0800248 __func__);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000249
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800250static inline void dma_write(u32 val, int reg, int lch)
251{
252 u8 stride;
253 u32 offset;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300254
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800255 stride = (reg >= dma_common_ch_start) ? dma_stride : 0;
256 offset = reg_map[reg] + (stride * lch);
257
258 if (dma_stride == 0x40) {
259 __raw_writew(val, omap_dma_base + offset);
260 if ((reg > CLNK_CTRL && reg < CCEN) ||
261 (reg > PCHD_ID && reg < CAPS_2)) {
262 u32 offset2 = reg_map[reg] + 2 + (stride * lch);
263 __raw_writew(val >> 16, omap_dma_base + offset2);
264 }
265 } else {
266 __raw_writel(val, omap_dma_base + offset);
267 }
268}
269
270static inline u32 dma_read(int reg, int lch)
271{
272 u8 stride;
273 u32 offset, val;
274
275 stride = (reg >= dma_common_ch_start) ? dma_stride : 0;
276 offset = reg_map[reg] + (stride * lch);
277
278 if (dma_stride == 0x40) {
279 val = __raw_readw(omap_dma_base + offset);
280 if ((reg > CLNK_CTRL && reg < CCEN) ||
281 (reg > PCHD_ID && reg < CAPS_2)) {
282 u16 upper;
283 u32 offset2 = reg_map[reg] + 2 + (stride * lch);
284 upper = __raw_readw(omap_dma_base + offset2);
285 val |= (upper << 16);
286 }
287 } else {
288 val = __raw_readl(omap_dma_base + offset);
289 }
290 return val;
291}
Tony Lindgren0499bde2008-07-03 12:24:36 +0300292
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000293#ifdef CONFIG_ARCH_OMAP15XX
294/* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */
Aaro Koskinene6f16822010-11-18 19:59:47 +0200295static int omap_dma_in_1510_mode(void)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000296{
297 return enable_1510_mode;
298}
299#else
300#define omap_dma_in_1510_mode() 0
301#endif
302
303#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100304static inline int get_gdma_dev(int req)
305{
306 u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
307 int shift = ((req - 1) % 5) * 6;
308
309 return ((omap_readl(reg) >> shift) & 0x3f) + 1;
310}
311
312static inline void set_gdma_dev(int req, int dev)
313{
314 u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
315 int shift = ((req - 1) % 5) * 6;
316 u32 l;
317
318 l = omap_readl(reg);
319 l &= ~(0x3f << shift);
320 l |= (dev - 1) << shift;
321 omap_writel(l, reg);
322}
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000323#else
324#define set_gdma_dev(req, dev) do {} while (0)
325#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100326
Tony Lindgren0499bde2008-07-03 12:24:36 +0300327/* Omap1 only */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100328static void clear_lch_regs(int lch)
329{
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800330 int i = dma_common_ch_start;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100331
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800332 for (; i <= dma_common_ch_end; i += 1)
333 dma_write(0, i, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100334}
335
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300336void omap_set_dma_priority(int lch, int dst_port, int priority)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100337{
338 unsigned long reg;
339 u32 l;
340
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300341 if (cpu_class_is_omap1()) {
342 switch (dst_port) {
343 case OMAP_DMA_PORT_OCP_T1: /* FFFECC00 */
344 reg = OMAP_TC_OCPT1_PRIOR;
345 break;
346 case OMAP_DMA_PORT_OCP_T2: /* FFFECCD0 */
347 reg = OMAP_TC_OCPT2_PRIOR;
348 break;
349 case OMAP_DMA_PORT_EMIFF: /* FFFECC08 */
350 reg = OMAP_TC_EMIFF_PRIOR;
351 break;
352 case OMAP_DMA_PORT_EMIFS: /* FFFECC04 */
353 reg = OMAP_TC_EMIFS_PRIOR;
354 break;
355 default:
356 BUG();
357 return;
358 }
359 l = omap_readl(reg);
360 l &= ~(0xf << 8);
361 l |= (priority & 0xf) << 8;
362 omap_writel(l, reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100363 }
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300364
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800365 if (cpu_class_is_omap2()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300366 u32 ccr;
367
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800368 ccr = dma_read(CCR, lch);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300369 if (priority)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300370 ccr |= (1 << 6);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300371 else
Tony Lindgren0499bde2008-07-03 12:24:36 +0300372 ccr &= ~(1 << 6);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800373 dma_write(ccr, CCR, lch);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300374 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100375}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300376EXPORT_SYMBOL(omap_set_dma_priority);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100377
378void omap_set_dma_transfer_params(int lch, int data_type, int elem_count,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000379 int frame_count, int sync_mode,
380 int dma_trigger, int src_or_dst_synch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100381{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300382 u32 l;
383
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800384 l = dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300385 l &= ~0x03;
386 l |= data_type;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800387 dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100388
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000389 if (cpu_class_is_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300390 u16 ccr;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100391
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800392 ccr = dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300393 ccr &= ~(1 << 5);
394 if (sync_mode == OMAP_DMA_SYNC_FRAME)
395 ccr |= 1 << 5;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800396 dma_write(ccr, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300397
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800398 ccr = dma_read(CCR2, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300399 ccr &= ~(1 << 2);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000400 if (sync_mode == OMAP_DMA_SYNC_BLOCK)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300401 ccr |= 1 << 2;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800402 dma_write(ccr, CCR2, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000403 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100404
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800405 if (cpu_class_is_omap2() && dma_trigger) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300406 u32 val;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100407
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800408 val = dma_read(CCR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100409
Anand Gadiyar4b3cf442009-01-15 13:09:53 +0200410 /* DMA_SYNCHRO_CONTROL_UPPER depends on the channel number */
Samu Onkalo72a11792010-08-02 14:21:40 +0300411 val &= ~((1 << 23) | (3 << 19) | 0x1f);
Anand Gadiyar4b3cf442009-01-15 13:09:53 +0200412 val |= (dma_trigger & ~0x1f) << 14;
413 val |= dma_trigger & 0x1f;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000414
415 if (sync_mode & OMAP_DMA_SYNC_FRAME)
416 val |= 1 << 5;
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700417 else
418 val &= ~(1 << 5);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000419
420 if (sync_mode & OMAP_DMA_SYNC_BLOCK)
421 val |= 1 << 18;
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700422 else
423 val &= ~(1 << 18);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000424
Samu Onkalo72a11792010-08-02 14:21:40 +0300425 if (src_or_dst_synch == OMAP_DMA_DST_SYNC_PREFETCH) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000426 val &= ~(1 << 24); /* dest synch */
Samu Onkalo72a11792010-08-02 14:21:40 +0300427 val |= (1 << 23); /* Prefetch */
428 } else if (src_or_dst_synch) {
429 val |= 1 << 24; /* source synch */
430 } else {
431 val &= ~(1 << 24); /* dest synch */
432 }
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800433 dma_write(val, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000434 }
435
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800436 dma_write(elem_count, CEN, lch);
437 dma_write(frame_count, CFN, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100438}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300439EXPORT_SYMBOL(omap_set_dma_transfer_params);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000440
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100441void omap_set_dma_color_mode(int lch, enum omap_dma_color_mode mode, u32 color)
442{
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100443 BUG_ON(omap_dma_in_1510_mode());
444
Tomi Valkeinen0815f8e2009-05-28 13:23:51 -0700445 if (cpu_class_is_omap1()) {
446 u16 w;
447
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800448 w = dma_read(CCR2, lch);
Tomi Valkeinen0815f8e2009-05-28 13:23:51 -0700449 w &= ~0x03;
450
451 switch (mode) {
452 case OMAP_DMA_CONSTANT_FILL:
453 w |= 0x01;
454 break;
455 case OMAP_DMA_TRANSPARENT_COPY:
456 w |= 0x02;
457 break;
458 case OMAP_DMA_COLOR_DIS:
459 break;
460 default:
461 BUG();
462 }
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800463 dma_write(w, CCR2, lch);
Tomi Valkeinen0815f8e2009-05-28 13:23:51 -0700464
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800465 w = dma_read(LCH_CTRL, lch);
Tomi Valkeinen0815f8e2009-05-28 13:23:51 -0700466 w &= ~0x0f;
467 /* Default is channel type 2D */
468 if (mode) {
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800469 dma_write(color, COLOR, lch);
Tomi Valkeinen0815f8e2009-05-28 13:23:51 -0700470 w |= 1; /* Channel type G */
471 }
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800472 dma_write(w, LCH_CTRL, lch);
Tomi Valkeinen0815f8e2009-05-28 13:23:51 -0700473 }
474
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800475 if (cpu_class_is_omap2()) {
Tomi Valkeinen0815f8e2009-05-28 13:23:51 -0700476 u32 val;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000477
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800478 val = dma_read(CCR, lch);
Tomi Valkeinen0815f8e2009-05-28 13:23:51 -0700479 val &= ~((1 << 17) | (1 << 16));
Tony Lindgren0499bde2008-07-03 12:24:36 +0300480
Tomi Valkeinen0815f8e2009-05-28 13:23:51 -0700481 switch (mode) {
482 case OMAP_DMA_CONSTANT_FILL:
483 val |= 1 << 16;
484 break;
485 case OMAP_DMA_TRANSPARENT_COPY:
486 val |= 1 << 17;
487 break;
488 case OMAP_DMA_COLOR_DIS:
489 break;
490 default:
491 BUG();
492 }
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800493 dma_write(val, CCR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100494
Tomi Valkeinen0815f8e2009-05-28 13:23:51 -0700495 color &= 0xffffff;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800496 dma_write(color, COLOR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100497 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100498}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300499EXPORT_SYMBOL(omap_set_dma_color_mode);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100500
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300501void omap_set_dma_write_mode(int lch, enum omap_dma_write_mode mode)
502{
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800503 if (cpu_class_is_omap2()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300504 u32 csdp;
505
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800506 csdp = dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300507 csdp &= ~(0x3 << 16);
508 csdp |= (mode << 16);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800509 dma_write(csdp, CSDP, lch);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300510 }
511}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300512EXPORT_SYMBOL(omap_set_dma_write_mode);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300513
Tony Lindgren0499bde2008-07-03 12:24:36 +0300514void omap_set_dma_channel_mode(int lch, enum omap_dma_channel_mode mode)
515{
516 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
517 u32 l;
518
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800519 l = dma_read(LCH_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300520 l &= ~0x7;
521 l |= mode;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800522 dma_write(l, LCH_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300523 }
524}
525EXPORT_SYMBOL(omap_set_dma_channel_mode);
526
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000527/* Note that src_port is only for omap1 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100528void omap_set_dma_src_params(int lch, int src_port, int src_amode,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000529 unsigned long src_start,
530 int src_ei, int src_fi)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100531{
Tony Lindgren97b7f712008-07-03 12:24:37 +0300532 u32 l;
533
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000534 if (cpu_class_is_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300535 u16 w;
536
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800537 w = dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300538 w &= ~(0x1f << 2);
539 w |= src_port << 2;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800540 dma_write(w, CSDP, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300541 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300542
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800543 l = dma_read(CCR, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300544 l &= ~(0x03 << 12);
545 l |= src_amode << 12;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800546 dma_write(l, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300547
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800548 dma_write(src_start, CSSA, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100549
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800550 dma_write(src_ei, CSEI, lch);
551 dma_write(src_fi, CSFI, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300552}
553EXPORT_SYMBOL(omap_set_dma_src_params);
554
555void omap_set_dma_params(int lch, struct omap_dma_channel_params *params)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000556{
557 omap_set_dma_transfer_params(lch, params->data_type,
558 params->elem_count, params->frame_count,
559 params->sync_mode, params->trigger,
560 params->src_or_dst_synch);
561 omap_set_dma_src_params(lch, params->src_port,
562 params->src_amode, params->src_start,
563 params->src_ei, params->src_fi);
564
565 omap_set_dma_dest_params(lch, params->dst_port,
566 params->dst_amode, params->dst_start,
567 params->dst_ei, params->dst_fi);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800568 if (params->read_prio || params->write_prio)
569 omap_dma_set_prio_lch(lch, params->read_prio,
570 params->write_prio);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100571}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300572EXPORT_SYMBOL(omap_set_dma_params);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100573
574void omap_set_dma_src_index(int lch, int eidx, int fidx)
575{
Tony Lindgren97b7f712008-07-03 12:24:37 +0300576 if (cpu_class_is_omap2())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000577 return;
Tony Lindgren97b7f712008-07-03 12:24:37 +0300578
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800579 dma_write(eidx, CSEI, lch);
580 dma_write(fidx, CSFI, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100581}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300582EXPORT_SYMBOL(omap_set_dma_src_index);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100583
584void omap_set_dma_src_data_pack(int lch, int enable)
585{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300586 u32 l;
587
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800588 l = dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300589 l &= ~(1 << 6);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000590 if (enable)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300591 l |= (1 << 6);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800592 dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100593}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300594EXPORT_SYMBOL(omap_set_dma_src_data_pack);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100595
596void omap_set_dma_src_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
597{
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700598 unsigned int burst = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300599 u32 l;
600
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800601 l = dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300602 l &= ~(0x03 << 7);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100603
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100604 switch (burst_mode) {
605 case OMAP_DMA_DATA_BURST_DIS:
606 break;
607 case OMAP_DMA_DATA_BURST_4:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800608 if (cpu_class_is_omap2())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700609 burst = 0x1;
610 else
611 burst = 0x2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100612 break;
613 case OMAP_DMA_DATA_BURST_8:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800614 if (cpu_class_is_omap2()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700615 burst = 0x2;
616 break;
617 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700618 /*
619 * not supported by current hardware on OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100620 * w |= (0x03 << 7);
621 * fall through
622 */
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700623 case OMAP_DMA_DATA_BURST_16:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800624 if (cpu_class_is_omap2()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700625 burst = 0x3;
626 break;
627 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700628 /*
629 * OMAP1 don't support burst 16
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700630 * fall through
631 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100632 default:
633 BUG();
634 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300635
636 l |= (burst << 7);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800637 dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100638}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300639EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100640
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000641/* Note that dest_port is only for OMAP1 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100642void omap_set_dma_dest_params(int lch, int dest_port, int dest_amode,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000643 unsigned long dest_start,
644 int dst_ei, int dst_fi)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100645{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300646 u32 l;
647
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000648 if (cpu_class_is_omap1()) {
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800649 l = dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300650 l &= ~(0x1f << 9);
651 l |= dest_port << 9;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800652 dma_write(l, CSDP, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000653 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100654
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800655 l = dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300656 l &= ~(0x03 << 14);
657 l |= dest_amode << 14;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800658 dma_write(l, CCR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100659
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800660 dma_write(dest_start, CDSA, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100661
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800662 dma_write(dst_ei, CDEI, lch);
663 dma_write(dst_fi, CDFI, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100664}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300665EXPORT_SYMBOL(omap_set_dma_dest_params);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100666
667void omap_set_dma_dest_index(int lch, int eidx, int fidx)
668{
Tony Lindgren97b7f712008-07-03 12:24:37 +0300669 if (cpu_class_is_omap2())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000670 return;
Tony Lindgren97b7f712008-07-03 12:24:37 +0300671
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800672 dma_write(eidx, CDEI, lch);
673 dma_write(fidx, CDFI, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100674}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300675EXPORT_SYMBOL(omap_set_dma_dest_index);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100676
677void omap_set_dma_dest_data_pack(int lch, int enable)
678{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300679 u32 l;
680
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800681 l = dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300682 l &= ~(1 << 13);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000683 if (enable)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300684 l |= 1 << 13;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800685 dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100686}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300687EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100688
689void omap_set_dma_dest_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
690{
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700691 unsigned int burst = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300692 u32 l;
693
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800694 l = dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300695 l &= ~(0x03 << 14);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100696
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100697 switch (burst_mode) {
698 case OMAP_DMA_DATA_BURST_DIS:
699 break;
700 case OMAP_DMA_DATA_BURST_4:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800701 if (cpu_class_is_omap2())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700702 burst = 0x1;
703 else
704 burst = 0x2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100705 break;
706 case OMAP_DMA_DATA_BURST_8:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800707 if (cpu_class_is_omap2())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700708 burst = 0x2;
709 else
710 burst = 0x3;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100711 break;
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700712 case OMAP_DMA_DATA_BURST_16:
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800713 if (cpu_class_is_omap2()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700714 burst = 0x3;
715 break;
716 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700717 /*
718 * OMAP1 don't support burst 16
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700719 * fall through
720 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100721 default:
722 printk(KERN_ERR "Invalid DMA burst mode\n");
723 BUG();
724 return;
725 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300726 l |= (burst << 14);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800727 dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100728}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300729EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100730
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000731static inline void omap_enable_channel_irq(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100732{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000733 u32 status;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100734
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700735 /* Clear CSR */
736 if (cpu_class_is_omap1())
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800737 status = dma_read(CSR, lch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800738 else if (cpu_class_is_omap2())
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800739 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000740
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100741 /* Enable some nice interrupts. */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800742 dma_write(dma_chan[lch].enabled_irqs, CICR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100743}
744
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000745static void omap_disable_channel_irq(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100746{
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800747 if (cpu_class_is_omap2())
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800748 dma_write(0, CICR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100749}
750
751void omap_enable_dma_irq(int lch, u16 bits)
752{
753 dma_chan[lch].enabled_irqs |= bits;
754}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300755EXPORT_SYMBOL(omap_enable_dma_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100756
757void omap_disable_dma_irq(int lch, u16 bits)
758{
759 dma_chan[lch].enabled_irqs &= ~bits;
760}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300761EXPORT_SYMBOL(omap_disable_dma_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100762
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000763static inline void enable_lnk(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100764{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300765 u32 l;
766
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800767 l = dma_read(CLNK_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300768
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000769 if (cpu_class_is_omap1())
Tony Lindgren0499bde2008-07-03 12:24:36 +0300770 l &= ~(1 << 14);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100771
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000772 /* Set the ENABLE_LNK bits */
773 if (dma_chan[lch].next_lch != -1)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300774 l = dma_chan[lch].next_lch | (1 << 15);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800775
776#ifndef CONFIG_ARCH_OMAP1
Tony Lindgren97b7f712008-07-03 12:24:37 +0300777 if (cpu_class_is_omap2())
778 if (dma_chan[lch].next_linked_ch != -1)
779 l = dma_chan[lch].next_linked_ch | (1 << 15);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800780#endif
Tony Lindgren0499bde2008-07-03 12:24:36 +0300781
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800782 dma_write(l, CLNK_CTRL, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100783}
784
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000785static inline void disable_lnk(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100786{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300787 u32 l;
788
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800789 l = dma_read(CLNK_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300790
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000791 /* Disable interrupts */
792 if (cpu_class_is_omap1()) {
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800793 dma_write(0, CICR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000794 /* Set the STOP_LNK bit */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300795 l |= 1 << 14;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100796 }
797
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800798 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000799 omap_disable_channel_irq(lch);
800 /* Clear the ENABLE_LNK bit */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300801 l &= ~(1 << 15);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000802 }
803
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800804 dma_write(l, CLNK_CTRL, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000805 dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
806}
807
808static inline void omap2_enable_irq_lch(int lch)
809{
810 u32 val;
Tao Huee907322009-11-10 18:55:17 -0800811 unsigned long flags;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000812
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800813 if (!cpu_class_is_omap2())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000814 return;
815
Tao Huee907322009-11-10 18:55:17 -0800816 spin_lock_irqsave(&dma_chan_lock, flags);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800817 val = dma_read(IRQENABLE_L0, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000818 val |= 1 << lch;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800819 dma_write(val, IRQENABLE_L0, lch);
Tao Huee907322009-11-10 18:55:17 -0800820 spin_unlock_irqrestore(&dma_chan_lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100821}
822
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700823static inline void omap2_disable_irq_lch(int lch)
824{
825 u32 val;
826 unsigned long flags;
827
828 if (!cpu_class_is_omap2())
829 return;
830
831 spin_lock_irqsave(&dma_chan_lock, flags);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800832 val = dma_read(IRQENABLE_L0, lch);
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700833 val &= ~(1 << lch);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800834 dma_write(val, IRQENABLE_L0, lch);
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700835 spin_unlock_irqrestore(&dma_chan_lock, flags);
836}
837
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100838int omap_request_dma(int dev_id, const char *dev_name,
Tony Lindgren97b7f712008-07-03 12:24:37 +0300839 void (*callback)(int lch, u16 ch_status, void *data),
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100840 void *data, int *dma_ch_out)
841{
842 int ch, free_ch = -1;
843 unsigned long flags;
844 struct omap_dma_lch *chan;
845
846 spin_lock_irqsave(&dma_chan_lock, flags);
847 for (ch = 0; ch < dma_chan_count; ch++) {
848 if (free_ch == -1 && dma_chan[ch].dev_id == -1) {
849 free_ch = ch;
850 if (dev_id == 0)
851 break;
852 }
853 }
854 if (free_ch == -1) {
855 spin_unlock_irqrestore(&dma_chan_lock, flags);
856 return -EBUSY;
857 }
858 chan = dma_chan + free_ch;
859 chan->dev_id = dev_id;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000860
861 if (cpu_class_is_omap1())
862 clear_lch_regs(free_ch);
863
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800864 if (cpu_class_is_omap2())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000865 omap_clear_dma(free_ch);
866
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100867 spin_unlock_irqrestore(&dma_chan_lock, flags);
868
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100869 chan->dev_name = dev_name;
870 chan->callback = callback;
871 chan->data = data;
Jarkko Nikulaa92fda12009-01-29 08:57:12 -0800872 chan->flags = 0;
Tony Lindgren97b7f712008-07-03 12:24:37 +0300873
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800874#ifndef CONFIG_ARCH_OMAP1
Tony Lindgren97b7f712008-07-03 12:24:37 +0300875 if (cpu_class_is_omap2()) {
876 chan->chain_id = -1;
877 chan->next_linked_ch = -1;
878 }
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800879#endif
Tony Lindgren97b7f712008-07-03 12:24:37 +0300880
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700881 chan->enabled_irqs = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000882
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700883 if (cpu_class_is_omap1())
884 chan->enabled_irqs |= OMAP1_DMA_TOUT_IRQ;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800885 else if (cpu_class_is_omap2())
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700886 chan->enabled_irqs |= OMAP2_DMA_MISALIGNED_ERR_IRQ |
887 OMAP2_DMA_TRANS_ERR_IRQ;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100888
889 if (cpu_is_omap16xx()) {
890 /* If the sync device is set, configure it dynamically. */
891 if (dev_id != 0) {
892 set_gdma_dev(free_ch + 1, dev_id);
893 dev_id = free_ch + 1;
894 }
Tony Lindgren97b7f712008-07-03 12:24:37 +0300895 /*
896 * Disable the 1510 compatibility mode and set the sync device
897 * id.
898 */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800899 dma_write(dev_id | (1 << 10), CCR, free_ch);
Zebediah C. McClure557096f2009-03-23 18:07:44 -0700900 } else if (cpu_is_omap7xx() || cpu_is_omap15xx()) {
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800901 dma_write(dev_id, CCR, free_ch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100902 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000903
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800904 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000905 omap2_enable_irq_lch(free_ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000906 omap_enable_channel_irq(free_ch);
907 /* Clear the CSR register and IRQ status register */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800908 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, free_ch);
909 dma_write(1 << free_ch, IRQSTATUS_L0, 0);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000910 }
911
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100912 *dma_ch_out = free_ch;
913
914 return 0;
915}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300916EXPORT_SYMBOL(omap_request_dma);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100917
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000918void omap_free_dma(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100919{
920 unsigned long flags;
921
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000922 if (dma_chan[lch].dev_id == -1) {
Tony Lindgren97b7f712008-07-03 12:24:37 +0300923 pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000924 lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100925 return;
926 }
Tony Lindgren97b7f712008-07-03 12:24:37 +0300927
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000928 if (cpu_class_is_omap1()) {
929 /* Disable all DMA interrupts for the channel. */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800930 dma_write(0, CICR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000931 /* Make sure the DMA transfer is stopped. */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800932 dma_write(0, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000933 }
934
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800935 if (cpu_class_is_omap2()) {
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700936 omap2_disable_irq_lch(lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000937
938 /* Clear the CSR register and IRQ status register */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800939 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch);
940 dma_write(1 << lch, IRQSTATUS_L0, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000941
942 /* Disable all DMA interrupts for the channel. */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800943 dma_write(0, CICR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000944
945 /* Make sure the DMA transfer is stopped. */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800946 dma_write(0, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000947 omap_clear_dma(lch);
948 }
Santosh Shilimkarda1b94e2009-04-23 11:10:40 -0700949
950 spin_lock_irqsave(&dma_chan_lock, flags);
951 dma_chan[lch].dev_id = -1;
952 dma_chan[lch].next_lch = -1;
953 dma_chan[lch].callback = NULL;
954 spin_unlock_irqrestore(&dma_chan_lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100955}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300956EXPORT_SYMBOL(omap_free_dma);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100957
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800958/**
959 * @brief omap_dma_set_global_params : Set global priority settings for dma
960 *
961 * @param arb_rate
962 * @param max_fifo_depth
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700963 * @param tparams - Number of threads to reserve : DMA_THREAD_RESERVE_NORM
964 * DMA_THREAD_RESERVE_ONET
965 * DMA_THREAD_RESERVE_TWOT
966 * DMA_THREAD_RESERVE_THREET
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800967 */
968void
969omap_dma_set_global_params(int arb_rate, int max_fifo_depth, int tparams)
970{
971 u32 reg;
972
973 if (!cpu_class_is_omap2()) {
Harvey Harrison8e86f422008-03-04 15:08:02 -0800974 printk(KERN_ERR "FIXME: no %s on 15xx/16xx\n", __func__);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800975 return;
976 }
977
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700978 if (max_fifo_depth == 0)
979 max_fifo_depth = 1;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800980 if (arb_rate == 0)
981 arb_rate = 1;
982
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700983 reg = 0xff & max_fifo_depth;
984 reg |= (0x3 & tparams) << 12;
985 reg |= (arb_rate & 0xff) << 16;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800986
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -0800987 dma_write(reg, GCR, 0);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800988}
989EXPORT_SYMBOL(omap_dma_set_global_params);
990
991/**
992 * @brief omap_dma_set_prio_lch : Set channel wise priority settings
993 *
994 * @param lch
995 * @param read_prio - Read priority
996 * @param write_prio - Write priority
997 * Both of the above can be set with one of the following values :
998 * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW
999 */
1000int
1001omap_dma_set_prio_lch(int lch, unsigned char read_prio,
1002 unsigned char write_prio)
1003{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001004 u32 l;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001005
Tony Lindgren4d963722008-07-03 12:24:31 +03001006 if (unlikely((lch < 0 || lch >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001007 printk(KERN_ERR "Invalid channel id\n");
1008 return -EINVAL;
1009 }
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001010 l = dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001011 l &= ~((1 << 6) | (1 << 26));
Santosh Shilimkar44169072009-05-28 14:16:04 -07001012 if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx())
Tony Lindgren0499bde2008-07-03 12:24:36 +03001013 l |= ((read_prio & 0x1) << 6) | ((write_prio & 0x1) << 26);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001014 else
Tony Lindgren0499bde2008-07-03 12:24:36 +03001015 l |= ((read_prio & 0x1) << 6);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001016
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001017 dma_write(l, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001018
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001019 return 0;
1020}
1021EXPORT_SYMBOL(omap_dma_set_prio_lch);
1022
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001023/*
1024 * Clears any DMA state so the DMA engine is ready to restart with new buffers
1025 * through omap_start_dma(). Any buffers in flight are discarded.
1026 */
1027void omap_clear_dma(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001028{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001029 unsigned long flags;
1030
1031 local_irq_save(flags);
1032
1033 if (cpu_class_is_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +03001034 u32 l;
1035
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001036 l = dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001037 l &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001038 dma_write(l, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001039
1040 /* Clear pending interrupts */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001041 l = dma_read(CSR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001042 }
1043
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001044 if (cpu_class_is_omap2()) {
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001045 int i = dma_common_ch_start;
1046 for (; i <= dma_common_ch_end; i += 1)
1047 dma_write(0, i, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001048 }
1049
1050 local_irq_restore(flags);
1051}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001052EXPORT_SYMBOL(omap_clear_dma);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001053
1054void omap_start_dma(int lch)
1055{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001056 u32 l;
1057
manjugk manjugk519e6162010-03-04 07:11:56 +00001058 /*
1059 * The CPC/CDAC register needs to be initialized to zero
1060 * before starting dma transfer.
1061 */
1062 if (cpu_is_omap15xx())
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001063 dma_write(0, CPC, lch);
manjugk manjugk519e6162010-03-04 07:11:56 +00001064 else
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001065 dma_write(0, CDAC, lch);
manjugk manjugk519e6162010-03-04 07:11:56 +00001066
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001067 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
1068 int next_lch, cur_lch;
Tony Lindgren4d963722008-07-03 12:24:31 +03001069 char dma_chan_link_map[OMAP_DMA4_LOGICAL_DMA_CH_COUNT];
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001070
1071 dma_chan_link_map[lch] = 1;
1072 /* Set the link register of the first channel */
1073 enable_lnk(lch);
1074
1075 memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
1076 cur_lch = dma_chan[lch].next_lch;
1077 do {
1078 next_lch = dma_chan[cur_lch].next_lch;
1079
1080 /* The loop case: we've been here already */
1081 if (dma_chan_link_map[cur_lch])
1082 break;
1083 /* Mark the current channel */
1084 dma_chan_link_map[cur_lch] = 1;
1085
1086 enable_lnk(cur_lch);
1087 omap_enable_channel_irq(cur_lch);
1088
1089 cur_lch = next_lch;
1090 } while (next_lch != -1);
Vikram Pandita284119c2009-08-10 14:49:50 +03001091 } else if (cpu_is_omap242x() ||
1092 (cpu_is_omap243x() && omap_type() <= OMAP2430_REV_ES1_0)) {
1093
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001094 /* Errata: Need to write lch even if not using chaining */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001095 dma_write(lch, CLNK_CTRL, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001096 }
1097
1098 omap_enable_channel_irq(lch);
1099
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001100 l = dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001101
Tony Lindgren97b7f712008-07-03 12:24:37 +03001102 /*
Jarkko Nikula3e57f162010-10-11 14:18:45 -07001103 * Errata: Inter Frame DMA buffering issue (All OMAP2420 and
1104 * OMAP2430ES1.0): DMA will wrongly buffer elements if packing and
1105 * bursting is enabled. This might result in data gets stalled in
1106 * FIFO at the end of the block.
1107 * Workaround: DMA channels must have BUFFERING_DISABLED bit set to
1108 * guarantee no data will stay in the DMA FIFO in case inter frame
1109 * buffering occurs.
Tony Lindgren97b7f712008-07-03 12:24:37 +03001110 */
Jarkko Nikula3e57f162010-10-11 14:18:45 -07001111 if (cpu_is_omap2420() ||
1112 (cpu_is_omap2430() && (omap_type() == OMAP2430_REV_ES1_0)))
1113 l |= OMAP_DMA_CCR_BUFFERING_DISABLE;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001114
Tony Lindgren0499bde2008-07-03 12:24:36 +03001115 l |= OMAP_DMA_CCR_EN;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001116 dma_write(l, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001117
1118 dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
1119}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001120EXPORT_SYMBOL(omap_start_dma);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001121
1122void omap_stop_dma(int lch)
1123{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001124 u32 l;
1125
Santosh Shilimkar9da65a92009-10-22 14:46:31 -07001126 /* Disable all interrupts on the channel */
1127 if (cpu_class_is_omap1())
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001128 dma_write(0, CICR, lch);
Santosh Shilimkar9da65a92009-10-22 14:46:31 -07001129
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001130 l = dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -07001131 /* OMAP3 Errata i541: sDMA FIFO draining does not finish */
1132 if (cpu_is_omap34xx() && (l & OMAP_DMA_CCR_SEL_SRC_DST_SYNC)) {
1133 int i = 0;
1134 u32 sys_cf;
1135
1136 /* Configure No-Standby */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001137 l = dma_read(OCP_SYSCONFIG, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -07001138 sys_cf = l;
1139 l &= ~DMA_SYSCONFIG_MIDLEMODE_MASK;
1140 l |= DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_NO_IDLE);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001141 dma_write(l , OCP_SYSCONFIG, 0);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -07001142
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001143 l = dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -07001144 l &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001145 dma_write(l, CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -07001146
1147 /* Wait for sDMA FIFO drain */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001148 l = dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -07001149 while (i < 100 && (l & (OMAP_DMA_CCR_RD_ACTIVE |
1150 OMAP_DMA_CCR_WR_ACTIVE))) {
1151 udelay(5);
1152 i++;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001153 l = dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -07001154 }
1155 if (i >= 100)
1156 printk(KERN_ERR "DMA drain did not complete on "
1157 "lch %d\n", lch);
1158 /* Restore OCP_SYSCONFIG */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001159 dma_write(sys_cf, OCP_SYSCONFIG, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -07001160 } else {
1161 l &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001162 dma_write(l, CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -07001163 }
Santosh Shilimkar9da65a92009-10-22 14:46:31 -07001164
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001165 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
1166 int next_lch, cur_lch = lch;
Tony Lindgren4d963722008-07-03 12:24:31 +03001167 char dma_chan_link_map[OMAP_DMA4_LOGICAL_DMA_CH_COUNT];
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001168
1169 memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
1170 do {
1171 /* The loop case: we've been here already */
1172 if (dma_chan_link_map[cur_lch])
1173 break;
1174 /* Mark the current channel */
1175 dma_chan_link_map[cur_lch] = 1;
1176
1177 disable_lnk(cur_lch);
1178
1179 next_lch = dma_chan[cur_lch].next_lch;
1180 cur_lch = next_lch;
1181 } while (next_lch != -1);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001182 }
1183
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001184 dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
1185}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001186EXPORT_SYMBOL(omap_stop_dma);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001187
1188/*
Tony Lindgren709eb3e52006-09-25 12:45:45 +03001189 * Allows changing the DMA callback function or data. This may be needed if
1190 * the driver shares a single DMA channel for multiple dma triggers.
1191 */
1192int omap_set_dma_callback(int lch,
Tony Lindgren97b7f712008-07-03 12:24:37 +03001193 void (*callback)(int lch, u16 ch_status, void *data),
Tony Lindgren709eb3e52006-09-25 12:45:45 +03001194 void *data)
1195{
1196 unsigned long flags;
1197
1198 if (lch < 0)
1199 return -ENODEV;
1200
1201 spin_lock_irqsave(&dma_chan_lock, flags);
1202 if (dma_chan[lch].dev_id == -1) {
1203 printk(KERN_ERR "DMA callback for not set for free channel\n");
1204 spin_unlock_irqrestore(&dma_chan_lock, flags);
1205 return -EINVAL;
1206 }
1207 dma_chan[lch].callback = callback;
1208 dma_chan[lch].data = data;
1209 spin_unlock_irqrestore(&dma_chan_lock, flags);
1210
1211 return 0;
1212}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001213EXPORT_SYMBOL(omap_set_dma_callback);
Tony Lindgren709eb3e52006-09-25 12:45:45 +03001214
1215/*
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001216 * Returns current physical source address for the given DMA channel.
1217 * If the channel is running the caller must disable interrupts prior calling
1218 * this function and process the returned value before re-enabling interrupt to
1219 * prevent races with the interrupt handler. Note that in continuous mode there
1220 * is a chance for CSSA_L register overflow inbetween the two reads resulting
1221 * in incorrect return value.
1222 */
1223dma_addr_t omap_get_dma_src_pos(int lch)
1224{
Tony Lindgren0695de32007-05-07 18:24:14 -07001225 dma_addr_t offset = 0;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001226
Tony Lindgren0499bde2008-07-03 12:24:36 +03001227 if (cpu_is_omap15xx())
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001228 offset = dma_read(CPC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001229 else
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001230 offset = dma_read(CSAC, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001231
Tony Lindgren0499bde2008-07-03 12:24:36 +03001232 /*
1233 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1234 * read before the DMA controller finished disabling the channel.
1235 */
1236 if (!cpu_is_omap15xx() && offset == 0)
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001237 offset = dma_read(CSAC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001238
1239 if (cpu_class_is_omap1())
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001240 offset |= (dma_read(CSSA, lch) & 0xFFFF0000);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001241
1242 return offset;
1243}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001244EXPORT_SYMBOL(omap_get_dma_src_pos);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001245
1246/*
1247 * Returns current physical destination address for the given DMA channel.
1248 * If the channel is running the caller must disable interrupts prior calling
1249 * this function and process the returned value before re-enabling interrupt to
1250 * prevent races with the interrupt handler. Note that in continuous mode there
1251 * is a chance for CDSA_L register overflow inbetween the two reads resulting
1252 * in incorrect return value.
1253 */
1254dma_addr_t omap_get_dma_dst_pos(int lch)
1255{
Tony Lindgren0695de32007-05-07 18:24:14 -07001256 dma_addr_t offset = 0;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001257
Tony Lindgren0499bde2008-07-03 12:24:36 +03001258 if (cpu_is_omap15xx())
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001259 offset = dma_read(CPC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001260 else
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001261 offset = dma_read(CDAC, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001262
Tony Lindgren0499bde2008-07-03 12:24:36 +03001263 /*
1264 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1265 * read before the DMA controller finished disabling the channel.
1266 */
1267 if (!cpu_is_omap15xx() && offset == 0)
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001268 offset = dma_read(CDAC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001269
1270 if (cpu_class_is_omap1())
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001271 offset |= (dma_read(CDSA, lch) & 0xFFFF0000);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001272
1273 return offset;
1274}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001275EXPORT_SYMBOL(omap_get_dma_dst_pos);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001276
Tony Lindgren0499bde2008-07-03 12:24:36 +03001277int omap_get_dma_active_status(int lch)
1278{
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001279 return (dma_read(CCR, lch) & OMAP_DMA_CCR_EN) != 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001280}
1281EXPORT_SYMBOL(omap_get_dma_active_status);
1282
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001283int omap_dma_running(void)
1284{
1285 int lch;
1286
Janusz Krzysztofikf8e9e982009-12-11 16:16:33 -08001287 if (cpu_class_is_omap1())
1288 if (omap_lcd_dma_running())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001289 return 1;
1290
1291 for (lch = 0; lch < dma_chan_count; lch++)
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001292 if (dma_read(CCR, lch) & OMAP_DMA_CCR_EN)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001293 return 1;
1294
1295 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001296}
1297
1298/*
1299 * lch_queue DMA will start right after lch_head one is finished.
1300 * For this DMA link to start, you still need to start (see omap_start_dma)
1301 * the first one. That will fire up the entire queue.
1302 */
Tony Lindgren97b7f712008-07-03 12:24:37 +03001303void omap_dma_link_lch(int lch_head, int lch_queue)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001304{
1305 if (omap_dma_in_1510_mode()) {
Janusz Krzysztofik9f0f4ae2009-08-23 17:56:12 +02001306 if (lch_head == lch_queue) {
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001307 dma_write(dma_read(CCR, lch_head) | (3 << 8),
1308 CCR, lch_head);
Janusz Krzysztofik9f0f4ae2009-08-23 17:56:12 +02001309 return;
1310 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001311 printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
1312 BUG();
1313 return;
1314 }
1315
1316 if ((dma_chan[lch_head].dev_id == -1) ||
1317 (dma_chan[lch_queue].dev_id == -1)) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001318 printk(KERN_ERR "omap_dma: trying to link "
1319 "non requested channels\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001320 dump_stack();
1321 }
1322
1323 dma_chan[lch_head].next_lch = lch_queue;
1324}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001325EXPORT_SYMBOL(omap_dma_link_lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001326
1327/*
1328 * Once the DMA queue is stopped, we can destroy it.
1329 */
Tony Lindgren97b7f712008-07-03 12:24:37 +03001330void omap_dma_unlink_lch(int lch_head, int lch_queue)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001331{
1332 if (omap_dma_in_1510_mode()) {
Janusz Krzysztofik9f0f4ae2009-08-23 17:56:12 +02001333 if (lch_head == lch_queue) {
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001334 dma_write(dma_read(CCR, lch_head) & ~(3 << 8),
1335 CCR, lch_head);
Janusz Krzysztofik9f0f4ae2009-08-23 17:56:12 +02001336 return;
1337 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001338 printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
1339 BUG();
1340 return;
1341 }
1342
1343 if (dma_chan[lch_head].next_lch != lch_queue ||
1344 dma_chan[lch_head].next_lch == -1) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001345 printk(KERN_ERR "omap_dma: trying to unlink "
1346 "non linked channels\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001347 dump_stack();
1348 }
1349
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001350 if ((dma_chan[lch_head].flags & OMAP_DMA_ACTIVE) ||
Roel Kluin247421f2010-01-13 18:10:29 -08001351 (dma_chan[lch_queue].flags & OMAP_DMA_ACTIVE)) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001352 printk(KERN_ERR "omap_dma: You need to stop the DMA channels "
1353 "before unlinking\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001354 dump_stack();
1355 }
1356
1357 dma_chan[lch_head].next_lch = -1;
1358}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001359EXPORT_SYMBOL(omap_dma_unlink_lch);
1360
1361/*----------------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001362
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001363#ifndef CONFIG_ARCH_OMAP1
1364/* Create chain of DMA channesls */
1365static void create_dma_lch_chain(int lch_head, int lch_queue)
1366{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001367 u32 l;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001368
1369 /* Check if this is the first link in chain */
1370 if (dma_chan[lch_head].next_linked_ch == -1) {
1371 dma_chan[lch_head].next_linked_ch = lch_queue;
1372 dma_chan[lch_head].prev_linked_ch = lch_queue;
1373 dma_chan[lch_queue].next_linked_ch = lch_head;
1374 dma_chan[lch_queue].prev_linked_ch = lch_head;
1375 }
1376
1377 /* a link exists, link the new channel in circular chain */
1378 else {
1379 dma_chan[lch_queue].next_linked_ch =
1380 dma_chan[lch_head].next_linked_ch;
1381 dma_chan[lch_queue].prev_linked_ch = lch_head;
1382 dma_chan[lch_head].next_linked_ch = lch_queue;
1383 dma_chan[dma_chan[lch_queue].next_linked_ch].prev_linked_ch =
1384 lch_queue;
1385 }
1386
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001387 l = dma_read(CLNK_CTRL, lch_head);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001388 l &= ~(0x1f);
1389 l |= lch_queue;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001390 dma_write(l, CLNK_CTRL, lch_head);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001391
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001392 l = dma_read(CLNK_CTRL, lch_queue);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001393 l &= ~(0x1f);
1394 l |= (dma_chan[lch_queue].next_linked_ch);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001395 dma_write(l, CLNK_CTRL, lch_queue);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001396}
1397
1398/**
1399 * @brief omap_request_dma_chain : Request a chain of DMA channels
1400 *
1401 * @param dev_id - Device id using the dma channel
1402 * @param dev_name - Device name
1403 * @param callback - Call back function
1404 * @chain_id -
1405 * @no_of_chans - Number of channels requested
1406 * @chain_mode - Dynamic or static chaining : OMAP_DMA_STATIC_CHAIN
1407 * OMAP_DMA_DYNAMIC_CHAIN
1408 * @params - Channel parameters
1409 *
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001410 * @return - Success : 0
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001411 * Failure: -EINVAL/-ENOMEM
1412 */
1413int omap_request_dma_chain(int dev_id, const char *dev_name,
Santosh Shilimkar279b9182009-05-28 13:23:52 -07001414 void (*callback) (int lch, u16 ch_status,
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001415 void *data),
1416 int *chain_id, int no_of_chans, int chain_mode,
1417 struct omap_dma_channel_params params)
1418{
1419 int *channels;
1420 int i, err;
1421
1422 /* Is the chain mode valid ? */
1423 if (chain_mode != OMAP_DMA_STATIC_CHAIN
1424 && chain_mode != OMAP_DMA_DYNAMIC_CHAIN) {
1425 printk(KERN_ERR "Invalid chain mode requested\n");
1426 return -EINVAL;
1427 }
1428
1429 if (unlikely((no_of_chans < 1
Tony Lindgren4d963722008-07-03 12:24:31 +03001430 || no_of_chans > dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001431 printk(KERN_ERR "Invalid Number of channels requested\n");
1432 return -EINVAL;
1433 }
1434
manjugk manjugkea221a62010-05-14 12:05:25 -07001435 /*
1436 * Allocate a queue to maintain the status of the channels
1437 * in the chain
1438 */
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001439 channels = kmalloc(sizeof(*channels) * no_of_chans, GFP_KERNEL);
1440 if (channels == NULL) {
1441 printk(KERN_ERR "omap_dma: No memory for channel queue\n");
1442 return -ENOMEM;
1443 }
1444
1445 /* request and reserve DMA channels for the chain */
1446 for (i = 0; i < no_of_chans; i++) {
1447 err = omap_request_dma(dev_id, dev_name,
Russell Kingc0fc18c52008-09-05 15:10:27 +01001448 callback, NULL, &channels[i]);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001449 if (err < 0) {
1450 int j;
1451 for (j = 0; j < i; j++)
1452 omap_free_dma(channels[j]);
1453 kfree(channels);
1454 printk(KERN_ERR "omap_dma: Request failed %d\n", err);
1455 return err;
1456 }
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001457 dma_chan[channels[i]].prev_linked_ch = -1;
1458 dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
1459
1460 /*
1461 * Allowing client drivers to set common parameters now,
1462 * so that later only relevant (src_start, dest_start
1463 * and element count) can be set
1464 */
1465 omap_set_dma_params(channels[i], &params);
1466 }
1467
1468 *chain_id = channels[0];
1469 dma_linked_lch[*chain_id].linked_dmach_q = channels;
1470 dma_linked_lch[*chain_id].chain_mode = chain_mode;
1471 dma_linked_lch[*chain_id].chain_state = DMA_CHAIN_NOTSTARTED;
1472 dma_linked_lch[*chain_id].no_of_lchs_linked = no_of_chans;
1473
1474 for (i = 0; i < no_of_chans; i++)
1475 dma_chan[channels[i]].chain_id = *chain_id;
1476
1477 /* Reset the Queue pointers */
1478 OMAP_DMA_CHAIN_QINIT(*chain_id);
1479
1480 /* Set up the chain */
1481 if (no_of_chans == 1)
1482 create_dma_lch_chain(channels[0], channels[0]);
1483 else {
1484 for (i = 0; i < (no_of_chans - 1); i++)
1485 create_dma_lch_chain(channels[i], channels[i + 1]);
1486 }
Tony Lindgren97b7f712008-07-03 12:24:37 +03001487
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001488 return 0;
1489}
1490EXPORT_SYMBOL(omap_request_dma_chain);
1491
1492/**
1493 * @brief omap_modify_dma_chain_param : Modify the chain's params - Modify the
1494 * params after setting it. Dont do this while dma is running!!
1495 *
1496 * @param chain_id - Chained logical channel id.
1497 * @param params
1498 *
1499 * @return - Success : 0
1500 * Failure : -EINVAL
1501 */
1502int omap_modify_dma_chain_params(int chain_id,
1503 struct omap_dma_channel_params params)
1504{
1505 int *channels;
1506 u32 i;
1507
1508 /* Check for input params */
1509 if (unlikely((chain_id < 0
Tony Lindgren4d963722008-07-03 12:24:31 +03001510 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001511 printk(KERN_ERR "Invalid chain id\n");
1512 return -EINVAL;
1513 }
1514
1515 /* Check if the chain exists */
1516 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1517 printk(KERN_ERR "Chain doesn't exists\n");
1518 return -EINVAL;
1519 }
1520 channels = dma_linked_lch[chain_id].linked_dmach_q;
1521
1522 for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
1523 /*
1524 * Allowing client drivers to set common parameters now,
1525 * so that later only relevant (src_start, dest_start
1526 * and element count) can be set
1527 */
1528 omap_set_dma_params(channels[i], &params);
1529 }
Tony Lindgren97b7f712008-07-03 12:24:37 +03001530
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001531 return 0;
1532}
1533EXPORT_SYMBOL(omap_modify_dma_chain_params);
1534
1535/**
1536 * @brief omap_free_dma_chain - Free all the logical channels in a chain.
1537 *
1538 * @param chain_id
1539 *
1540 * @return - Success : 0
1541 * Failure : -EINVAL
1542 */
1543int omap_free_dma_chain(int chain_id)
1544{
1545 int *channels;
1546 u32 i;
1547
1548 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001549 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001550 printk(KERN_ERR "Invalid chain id\n");
1551 return -EINVAL;
1552 }
1553
1554 /* Check if the chain exists */
1555 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1556 printk(KERN_ERR "Chain doesn't exists\n");
1557 return -EINVAL;
1558 }
1559
1560 channels = dma_linked_lch[chain_id].linked_dmach_q;
1561 for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
1562 dma_chan[channels[i]].next_linked_ch = -1;
1563 dma_chan[channels[i]].prev_linked_ch = -1;
1564 dma_chan[channels[i]].chain_id = -1;
1565 dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
1566 omap_free_dma(channels[i]);
1567 }
1568
1569 kfree(channels);
1570
1571 dma_linked_lch[chain_id].linked_dmach_q = NULL;
1572 dma_linked_lch[chain_id].chain_mode = -1;
1573 dma_linked_lch[chain_id].chain_state = -1;
Tony Lindgren97b7f712008-07-03 12:24:37 +03001574
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001575 return (0);
1576}
1577EXPORT_SYMBOL(omap_free_dma_chain);
1578
1579/**
1580 * @brief omap_dma_chain_status - Check if the chain is in
1581 * active / inactive state.
1582 * @param chain_id
1583 *
1584 * @return - Success : OMAP_DMA_CHAIN_ACTIVE/OMAP_DMA_CHAIN_INACTIVE
1585 * Failure : -EINVAL
1586 */
1587int omap_dma_chain_status(int chain_id)
1588{
1589 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001590 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001591 printk(KERN_ERR "Invalid chain id\n");
1592 return -EINVAL;
1593 }
1594
1595 /* Check if the chain exists */
1596 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1597 printk(KERN_ERR "Chain doesn't exists\n");
1598 return -EINVAL;
1599 }
1600 pr_debug("CHAINID=%d, qcnt=%d\n", chain_id,
1601 dma_linked_lch[chain_id].q_count);
1602
1603 if (OMAP_DMA_CHAIN_QEMPTY(chain_id))
1604 return OMAP_DMA_CHAIN_INACTIVE;
Tony Lindgren97b7f712008-07-03 12:24:37 +03001605
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001606 return OMAP_DMA_CHAIN_ACTIVE;
1607}
1608EXPORT_SYMBOL(omap_dma_chain_status);
1609
1610/**
1611 * @brief omap_dma_chain_a_transfer - Get a free channel from a chain,
1612 * set the params and start the transfer.
1613 *
1614 * @param chain_id
1615 * @param src_start - buffer start address
1616 * @param dest_start - Dest address
1617 * @param elem_count
1618 * @param frame_count
1619 * @param callbk_data - channel callback parameter data.
1620 *
Anand Gadiyarf4b6a7e2008-03-11 01:10:35 +05301621 * @return - Success : 0
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001622 * Failure: -EINVAL/-EBUSY
1623 */
1624int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start,
1625 int elem_count, int frame_count, void *callbk_data)
1626{
1627 int *channels;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001628 u32 l, lch;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001629 int start_dma = 0;
1630
Tony Lindgren97b7f712008-07-03 12:24:37 +03001631 /*
1632 * if buffer size is less than 1 then there is
1633 * no use of starting the chain
1634 */
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001635 if (elem_count < 1) {
1636 printk(KERN_ERR "Invalid buffer size\n");
1637 return -EINVAL;
1638 }
1639
1640 /* Check for input params */
1641 if (unlikely((chain_id < 0
Tony Lindgren4d963722008-07-03 12:24:31 +03001642 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001643 printk(KERN_ERR "Invalid chain id\n");
1644 return -EINVAL;
1645 }
1646
1647 /* Check if the chain exists */
1648 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1649 printk(KERN_ERR "Chain doesn't exist\n");
1650 return -EINVAL;
1651 }
1652
1653 /* Check if all the channels in chain are in use */
1654 if (OMAP_DMA_CHAIN_QFULL(chain_id))
1655 return -EBUSY;
1656
1657 /* Frame count may be negative in case of indexed transfers */
1658 channels = dma_linked_lch[chain_id].linked_dmach_q;
1659
1660 /* Get a free channel */
1661 lch = channels[dma_linked_lch[chain_id].q_tail];
1662
1663 /* Store the callback data */
1664 dma_chan[lch].data = callbk_data;
1665
1666 /* Increment the q_tail */
1667 OMAP_DMA_CHAIN_INCQTAIL(chain_id);
1668
1669 /* Set the params to the free channel */
1670 if (src_start != 0)
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001671 dma_write(src_start, CSSA, lch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001672 if (dest_start != 0)
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001673 dma_write(dest_start, CDSA, lch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001674
1675 /* Write the buffer size */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001676 dma_write(elem_count, CEN, lch);
1677 dma_write(frame_count, CFN, lch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001678
Tony Lindgren97b7f712008-07-03 12:24:37 +03001679 /*
1680 * If the chain is dynamically linked,
1681 * then we may have to start the chain if its not active
1682 */
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001683 if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_DYNAMIC_CHAIN) {
1684
Tony Lindgren97b7f712008-07-03 12:24:37 +03001685 /*
1686 * In Dynamic chain, if the chain is not started,
1687 * queue the channel
1688 */
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001689 if (dma_linked_lch[chain_id].chain_state ==
1690 DMA_CHAIN_NOTSTARTED) {
1691 /* Enable the link in previous channel */
1692 if (dma_chan[dma_chan[lch].prev_linked_ch].state ==
1693 DMA_CH_QUEUED)
1694 enable_lnk(dma_chan[lch].prev_linked_ch);
1695 dma_chan[lch].state = DMA_CH_QUEUED;
1696 }
1697
Tony Lindgren97b7f712008-07-03 12:24:37 +03001698 /*
1699 * Chain is already started, make sure its active,
1700 * if not then start the chain
1701 */
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001702 else {
1703 start_dma = 1;
1704
1705 if (dma_chan[dma_chan[lch].prev_linked_ch].state ==
1706 DMA_CH_STARTED) {
1707 enable_lnk(dma_chan[lch].prev_linked_ch);
1708 dma_chan[lch].state = DMA_CH_QUEUED;
1709 start_dma = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001710 if (0 == ((1 << 7) & dma_read(
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001711 CCR, dma_chan[lch].prev_linked_ch))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001712 disable_lnk(dma_chan[lch].
1713 prev_linked_ch);
1714 pr_debug("\n prev ch is stopped\n");
1715 start_dma = 1;
1716 }
1717 }
1718
1719 else if (dma_chan[dma_chan[lch].prev_linked_ch].state
1720 == DMA_CH_QUEUED) {
1721 enable_lnk(dma_chan[lch].prev_linked_ch);
1722 dma_chan[lch].state = DMA_CH_QUEUED;
1723 start_dma = 0;
1724 }
1725 omap_enable_channel_irq(lch);
1726
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001727 l = dma_read(CCR, lch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001728
Tony Lindgren0499bde2008-07-03 12:24:36 +03001729 if ((0 == (l & (1 << 24))))
1730 l &= ~(1 << 25);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001731 else
Tony Lindgren0499bde2008-07-03 12:24:36 +03001732 l |= (1 << 25);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001733 if (start_dma == 1) {
Tony Lindgren0499bde2008-07-03 12:24:36 +03001734 if (0 == (l & (1 << 7))) {
1735 l |= (1 << 7);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001736 dma_chan[lch].state = DMA_CH_STARTED;
1737 pr_debug("starting %d\n", lch);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001738 dma_write(l, CCR, lch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001739 } else
1740 start_dma = 0;
1741 } else {
Tony Lindgren0499bde2008-07-03 12:24:36 +03001742 if (0 == (l & (1 << 7)))
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001743 dma_write(l, CCR, lch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001744 }
1745 dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
1746 }
1747 }
Tony Lindgren97b7f712008-07-03 12:24:37 +03001748
Anand Gadiyarf4b6a7e2008-03-11 01:10:35 +05301749 return 0;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001750}
1751EXPORT_SYMBOL(omap_dma_chain_a_transfer);
1752
1753/**
1754 * @brief omap_start_dma_chain_transfers - Start the chain
1755 *
1756 * @param chain_id
1757 *
1758 * @return - Success : 0
1759 * Failure : -EINVAL/-EBUSY
1760 */
1761int omap_start_dma_chain_transfers(int chain_id)
1762{
1763 int *channels;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001764 u32 l, i;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001765
Tony Lindgren4d963722008-07-03 12:24:31 +03001766 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001767 printk(KERN_ERR "Invalid chain id\n");
1768 return -EINVAL;
1769 }
1770
1771 channels = dma_linked_lch[chain_id].linked_dmach_q;
1772
1773 if (dma_linked_lch[channels[0]].chain_state == DMA_CHAIN_STARTED) {
1774 printk(KERN_ERR "Chain is already started\n");
1775 return -EBUSY;
1776 }
1777
1778 if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_STATIC_CHAIN) {
1779 for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked;
1780 i++) {
1781 enable_lnk(channels[i]);
1782 omap_enable_channel_irq(channels[i]);
1783 }
1784 } else {
1785 omap_enable_channel_irq(channels[0]);
1786 }
1787
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001788 l = dma_read(CCR, channels[0]);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001789 l |= (1 << 7);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001790 dma_linked_lch[chain_id].chain_state = DMA_CHAIN_STARTED;
1791 dma_chan[channels[0]].state = DMA_CH_STARTED;
1792
Tony Lindgren0499bde2008-07-03 12:24:36 +03001793 if ((0 == (l & (1 << 24))))
1794 l &= ~(1 << 25);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001795 else
Tony Lindgren0499bde2008-07-03 12:24:36 +03001796 l |= (1 << 25);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001797 dma_write(l, CCR, channels[0]);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001798
1799 dma_chan[channels[0]].flags |= OMAP_DMA_ACTIVE;
Tony Lindgren97b7f712008-07-03 12:24:37 +03001800
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001801 return 0;
1802}
1803EXPORT_SYMBOL(omap_start_dma_chain_transfers);
1804
1805/**
1806 * @brief omap_stop_dma_chain_transfers - Stop the dma transfer of a chain.
1807 *
1808 * @param chain_id
1809 *
1810 * @return - Success : 0
1811 * Failure : EINVAL
1812 */
1813int omap_stop_dma_chain_transfers(int chain_id)
1814{
1815 int *channels;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001816 u32 l, i;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001817 u32 sys_cf;
1818
1819 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001820 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001821 printk(KERN_ERR "Invalid chain id\n");
1822 return -EINVAL;
1823 }
1824
1825 /* Check if the chain exists */
1826 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1827 printk(KERN_ERR "Chain doesn't exists\n");
1828 return -EINVAL;
1829 }
1830 channels = dma_linked_lch[chain_id].linked_dmach_q;
1831
Tony Lindgren97b7f712008-07-03 12:24:37 +03001832 /*
1833 * DMA Errata:
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001834 * Special programming model needed to disable DMA before end of block
1835 */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001836 sys_cf = dma_read(OCP_SYSCONFIG, 0);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001837 l = sys_cf;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001838 /* Middle mode reg set no Standby */
Tony Lindgren0499bde2008-07-03 12:24:36 +03001839 l &= ~((1 << 12)|(1 << 13));
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001840 dma_write(l, OCP_SYSCONFIG, 0);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001841
1842 for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
1843
1844 /* Stop the Channel transmission */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001845 l = dma_read(CCR, channels[i]);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001846 l &= ~(1 << 7);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001847 dma_write(l, CCR, channels[i]);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001848
1849 /* Disable the link in all the channels */
1850 disable_lnk(channels[i]);
1851 dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
1852
1853 }
1854 dma_linked_lch[chain_id].chain_state = DMA_CHAIN_NOTSTARTED;
1855
1856 /* Reset the Queue pointers */
1857 OMAP_DMA_CHAIN_QINIT(chain_id);
1858
1859 /* Errata - put in the old value */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001860 dma_write(sys_cf, OCP_SYSCONFIG, 0);
Tony Lindgren97b7f712008-07-03 12:24:37 +03001861
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001862 return 0;
1863}
1864EXPORT_SYMBOL(omap_stop_dma_chain_transfers);
1865
1866/* Get the index of the ongoing DMA in chain */
1867/**
1868 * @brief omap_get_dma_chain_index - Get the element and frame index
1869 * of the ongoing DMA in chain
1870 *
1871 * @param chain_id
1872 * @param ei - Element index
1873 * @param fi - Frame index
1874 *
1875 * @return - Success : 0
1876 * Failure : -EINVAL
1877 */
1878int omap_get_dma_chain_index(int chain_id, int *ei, int *fi)
1879{
1880 int lch;
1881 int *channels;
1882
1883 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001884 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001885 printk(KERN_ERR "Invalid chain id\n");
1886 return -EINVAL;
1887 }
1888
1889 /* Check if the chain exists */
1890 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1891 printk(KERN_ERR "Chain doesn't exists\n");
1892 return -EINVAL;
1893 }
1894 if ((!ei) || (!fi))
1895 return -EINVAL;
1896
1897 channels = dma_linked_lch[chain_id].linked_dmach_q;
1898
1899 /* Get the current channel */
1900 lch = channels[dma_linked_lch[chain_id].q_head];
1901
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001902 *ei = dma_read(CCEN, lch);
1903 *fi = dma_read(CCFN, lch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001904
1905 return 0;
1906}
1907EXPORT_SYMBOL(omap_get_dma_chain_index);
1908
1909/**
1910 * @brief omap_get_dma_chain_dst_pos - Get the destination position of the
1911 * ongoing DMA in chain
1912 *
1913 * @param chain_id
1914 *
1915 * @return - Success : Destination position
1916 * Failure : -EINVAL
1917 */
1918int omap_get_dma_chain_dst_pos(int chain_id)
1919{
1920 int lch;
1921 int *channels;
1922
1923 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001924 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001925 printk(KERN_ERR "Invalid chain id\n");
1926 return -EINVAL;
1927 }
1928
1929 /* Check if the chain exists */
1930 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1931 printk(KERN_ERR "Chain doesn't exists\n");
1932 return -EINVAL;
1933 }
1934
1935 channels = dma_linked_lch[chain_id].linked_dmach_q;
1936
1937 /* Get the current channel */
1938 lch = channels[dma_linked_lch[chain_id].q_head];
1939
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001940 return dma_read(CDAC, lch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001941}
1942EXPORT_SYMBOL(omap_get_dma_chain_dst_pos);
1943
1944/**
1945 * @brief omap_get_dma_chain_src_pos - Get the source position
1946 * of the ongoing DMA in chain
1947 * @param chain_id
1948 *
1949 * @return - Success : Destination position
1950 * Failure : -EINVAL
1951 */
1952int omap_get_dma_chain_src_pos(int chain_id)
1953{
1954 int lch;
1955 int *channels;
1956
1957 /* Check for input params */
Tony Lindgren4d963722008-07-03 12:24:31 +03001958 if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001959 printk(KERN_ERR "Invalid chain id\n");
1960 return -EINVAL;
1961 }
1962
1963 /* Check if the chain exists */
1964 if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
1965 printk(KERN_ERR "Chain doesn't exists\n");
1966 return -EINVAL;
1967 }
1968
1969 channels = dma_linked_lch[chain_id].linked_dmach_q;
1970
1971 /* Get the current channel */
1972 lch = channels[dma_linked_lch[chain_id].q_head];
1973
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001974 return dma_read(CSAC, lch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001975}
1976EXPORT_SYMBOL(omap_get_dma_chain_src_pos);
Tony Lindgren97b7f712008-07-03 12:24:37 +03001977#endif /* ifndef CONFIG_ARCH_OMAP1 */
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001978
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001979/*----------------------------------------------------------------------------*/
1980
1981#ifdef CONFIG_ARCH_OMAP1
1982
1983static int omap1_dma_handle_ch(int ch)
1984{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001985 u32 csr;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001986
1987 if (enable_1510_mode && ch >= 6) {
1988 csr = dma_chan[ch].saved_csr;
1989 dma_chan[ch].saved_csr = 0;
1990 } else
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001991 csr = dma_read(CSR, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001992 if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) {
1993 dma_chan[ch + 6].saved_csr = csr >> 7;
1994 csr &= 0x7f;
1995 }
1996 if ((csr & 0x3f) == 0)
1997 return 0;
1998 if (unlikely(dma_chan[ch].dev_id == -1)) {
1999 printk(KERN_WARNING "Spurious interrupt from DMA channel "
2000 "%d (CSR %04x)\n", ch, csr);
2001 return 0;
2002 }
Tony Lindgren7ff879d2006-06-26 16:16:15 -07002003 if (unlikely(csr & OMAP1_DMA_TOUT_IRQ))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002004 printk(KERN_WARNING "DMA timeout with device %d\n",
2005 dma_chan[ch].dev_id);
2006 if (unlikely(csr & OMAP_DMA_DROP_IRQ))
2007 printk(KERN_WARNING "DMA synchronization event drop occurred "
2008 "with device %d\n", dma_chan[ch].dev_id);
2009 if (likely(csr & OMAP_DMA_BLOCK_IRQ))
2010 dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
2011 if (likely(dma_chan[ch].callback != NULL))
2012 dma_chan[ch].callback(ch, csr, dma_chan[ch].data);
Tony Lindgren97b7f712008-07-03 12:24:37 +03002013
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002014 return 1;
2015}
2016
Linus Torvalds0cd61b62006-10-06 10:53:39 -07002017static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002018{
2019 int ch = ((int) dev_id) - 1;
2020 int handled = 0;
2021
2022 for (;;) {
2023 int handled_now = 0;
2024
2025 handled_now += omap1_dma_handle_ch(ch);
2026 if (enable_1510_mode && dma_chan[ch + 6].saved_csr)
2027 handled_now += omap1_dma_handle_ch(ch + 6);
2028 if (!handled_now)
2029 break;
2030 handled += handled_now;
2031 }
2032
2033 return handled ? IRQ_HANDLED : IRQ_NONE;
2034}
2035
2036#else
2037#define omap1_dma_irq_handler NULL
2038#endif
2039
Tony Lindgren140455f2010-02-12 12:26:48 -08002040#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002041
2042static int omap2_dma_handle_ch(int ch)
2043{
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002044 u32 status = dma_read(CSR, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002045
Juha Yrjola31513692006-12-06 17:13:47 -08002046 if (!status) {
2047 if (printk_ratelimit())
Tony Lindgren97b7f712008-07-03 12:24:37 +03002048 printk(KERN_WARNING "Spurious DMA IRQ for lch %d\n",
2049 ch);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002050 dma_write(1 << ch, IRQSTATUS_L0, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002051 return 0;
Juha Yrjola31513692006-12-06 17:13:47 -08002052 }
2053 if (unlikely(dma_chan[ch].dev_id == -1)) {
2054 if (printk_ratelimit())
2055 printk(KERN_WARNING "IRQ %04x for non-allocated DMA"
2056 "channel %d\n", status, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002057 return 0;
Juha Yrjola31513692006-12-06 17:13:47 -08002058 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002059 if (unlikely(status & OMAP_DMA_DROP_IRQ))
2060 printk(KERN_INFO
2061 "DMA synchronization event drop occurred with device "
2062 "%d\n", dma_chan[ch].dev_id);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08002063 if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ)) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002064 printk(KERN_INFO "DMA transaction error with device %d\n",
2065 dma_chan[ch].dev_id);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08002066 if (cpu_class_is_omap2()) {
manjugk manjugkea221a62010-05-14 12:05:25 -07002067 /*
2068 * Errata: sDMA Channel is not disabled
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08002069 * after a transaction error. So we explicitely
2070 * disable the channel
2071 */
2072 u32 ccr;
2073
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002074 ccr = dma_read(CCR, ch);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08002075 ccr &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002076 dma_write(ccr, CCR, ch);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08002077 dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
2078 }
2079 }
Tony Lindgren7ff879d2006-06-26 16:16:15 -07002080 if (unlikely(status & OMAP2_DMA_SECURE_ERR_IRQ))
2081 printk(KERN_INFO "DMA secure error with device %d\n",
2082 dma_chan[ch].dev_id);
2083 if (unlikely(status & OMAP2_DMA_MISALIGNED_ERR_IRQ))
2084 printk(KERN_INFO "DMA misaligned error with device %d\n",
2085 dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002086
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002087 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, ch);
2088 dma_write(1 << ch, IRQSTATUS_L0, ch);
Mathias Nymane860e6d2010-10-25 14:35:24 +00002089 /* read back the register to flush the write */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002090 dma_read(IRQSTATUS_L0, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002091
Anand Gadiyarf8151e52007-12-01 12:14:11 -08002092 /* If the ch is not chained then chain_id will be -1 */
2093 if (dma_chan[ch].chain_id != -1) {
2094 int chain_id = dma_chan[ch].chain_id;
2095 dma_chan[ch].state = DMA_CH_NOTSTARTED;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002096 if (dma_read(CLNK_CTRL, ch) & (1 << 15))
Anand Gadiyarf8151e52007-12-01 12:14:11 -08002097 dma_chan[dma_chan[ch].next_linked_ch].state =
2098 DMA_CH_STARTED;
2099 if (dma_linked_lch[chain_id].chain_mode ==
2100 OMAP_DMA_DYNAMIC_CHAIN)
2101 disable_lnk(ch);
2102
2103 if (!OMAP_DMA_CHAIN_QEMPTY(chain_id))
2104 OMAP_DMA_CHAIN_INCQHEAD(chain_id);
2105
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002106 status = dma_read(CSR, ch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08002107 }
2108
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002109 dma_write(status, CSR, ch);
Juha Yrjola320ce6f2009-01-29 08:57:12 -08002110
Jarkko Nikula538528d2008-02-13 11:47:29 +02002111 if (likely(dma_chan[ch].callback != NULL))
2112 dma_chan[ch].callback(ch, status, dma_chan[ch].data);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08002113
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002114 return 0;
2115}
2116
2117/* STATUS register count is from 1-32 while our is 0-31 */
Linus Torvalds0cd61b62006-10-06 10:53:39 -07002118static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002119{
Santosh Shilimkar52176e72009-03-23 18:07:49 -07002120 u32 val, enable_reg;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002121 int i;
2122
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002123 val = dma_read(IRQSTATUS_L0, 0);
Juha Yrjola31513692006-12-06 17:13:47 -08002124 if (val == 0) {
2125 if (printk_ratelimit())
2126 printk(KERN_WARNING "Spurious DMA IRQ\n");
2127 return IRQ_HANDLED;
2128 }
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002129 enable_reg = dma_read(IRQENABLE_L0, 0);
Santosh Shilimkar52176e72009-03-23 18:07:49 -07002130 val &= enable_reg; /* Dispatch only relevant interrupts */
Tony Lindgren4d963722008-07-03 12:24:31 +03002131 for (i = 0; i < dma_lch_count && val != 0; i++) {
Juha Yrjola31513692006-12-06 17:13:47 -08002132 if (val & 1)
2133 omap2_dma_handle_ch(i);
2134 val >>= 1;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002135 }
2136
2137 return IRQ_HANDLED;
2138}
2139
2140static struct irqaction omap24xx_dma_irq = {
2141 .name = "DMA",
2142 .handler = omap2_dma_irq_handler,
Thomas Gleixner52e405e2006-07-03 02:20:05 +02002143 .flags = IRQF_DISABLED
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002144};
2145
2146#else
2147static struct irqaction omap24xx_dma_irq;
2148#endif
2149
2150/*----------------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002151
Tero Kristof2d11852008-08-28 13:13:31 +00002152void omap_dma_global_context_save(void)
2153{
2154 omap_dma_global_context.dma_irqenable_l0 =
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002155 dma_read(IRQENABLE_L0, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00002156 omap_dma_global_context.dma_ocp_sysconfig =
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002157 dma_read(OCP_SYSCONFIG, 0);
2158 omap_dma_global_context.dma_gcr = dma_read(GCR, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00002159}
2160
2161void omap_dma_global_context_restore(void)
2162{
Aaro Koskinenbf07c9f2009-05-20 16:58:30 +03002163 int ch;
2164
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002165 dma_write(omap_dma_global_context.dma_gcr, GCR, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00002166 dma_write(omap_dma_global_context.dma_ocp_sysconfig,
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002167 OCP_SYSCONFIG, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00002168 dma_write(omap_dma_global_context.dma_irqenable_l0,
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002169 IRQENABLE_L0, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00002170
Kalle Jokiniemiba50ea72009-03-26 15:59:00 +02002171 /*
2172 * A bug in ROM code leaves IRQ status for channels 0 and 1 uncleared
2173 * after secure sram context save and restore. Hence we need to
2174 * manually clear those IRQs to avoid spurious interrupts. This
2175 * affects only secure devices.
2176 */
2177 if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002178 dma_write(0x3 , IRQSTATUS_L0, 0);
Aaro Koskinenbf07c9f2009-05-20 16:58:30 +03002179
2180 for (ch = 0; ch < dma_chan_count; ch++)
2181 if (dma_chan[ch].dev_id != -1)
2182 omap_clear_dma(ch);
Tero Kristof2d11852008-08-28 13:13:31 +00002183}
2184
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002185/*----------------------------------------------------------------------------*/
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01002186
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002187static int __init omap_init_dma(void)
2188{
Tony Lindgren7e9bf842009-10-19 15:25:15 -07002189 unsigned long base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002190 int ch, r;
2191
Tony Lindgren0499bde2008-07-03 12:24:36 +03002192 if (cpu_class_is_omap1()) {
Tony Lindgren7e9bf842009-10-19 15:25:15 -07002193 base = OMAP1_DMA_BASE;
Tony Lindgren4d963722008-07-03 12:24:31 +03002194 dma_lch_count = OMAP1_LOGICAL_DMA_CH_COUNT;
Tony Lindgren0499bde2008-07-03 12:24:36 +03002195 } else if (cpu_is_omap24xx()) {
Tony Lindgren7e9bf842009-10-19 15:25:15 -07002196 base = OMAP24XX_DMA4_BASE;
Tony Lindgren4d963722008-07-03 12:24:31 +03002197 dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
Tony Lindgren0499bde2008-07-03 12:24:36 +03002198 } else if (cpu_is_omap34xx()) {
Tony Lindgren7e9bf842009-10-19 15:25:15 -07002199 base = OMAP34XX_DMA4_BASE;
Tony Lindgren0499bde2008-07-03 12:24:36 +03002200 dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
Santosh Shilimkar44169072009-05-28 14:16:04 -07002201 } else if (cpu_is_omap44xx()) {
Tony Lindgren7e9bf842009-10-19 15:25:15 -07002202 base = OMAP44XX_DMA4_BASE;
Santosh Shilimkar44169072009-05-28 14:16:04 -07002203 dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
Tony Lindgren0499bde2008-07-03 12:24:36 +03002204 } else {
2205 pr_err("DMA init failed for unsupported omap\n");
2206 return -ENODEV;
2207 }
Tony Lindgren4d963722008-07-03 12:24:31 +03002208
Tony Lindgren7e9bf842009-10-19 15:25:15 -07002209 omap_dma_base = ioremap(base, SZ_4K);
2210 BUG_ON(!omap_dma_base);
2211
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002212 if (cpu_class_is_omap1()) {
2213 dma_stride = 0x40;
2214 reg_map = reg_map_omap1;
2215 dma_common_ch_start = CPC;
2216 dma_common_ch_end = COLOR;
2217 } else {
2218 dma_stride = 0x60;
2219 reg_map = reg_map_omap2;
2220 dma_common_ch_start = CSDP;
2221 if (cpu_is_omap3630() || cpu_is_omap4430())
2222 dma_common_ch_end = CCDN;
2223 else
2224 dma_common_ch_end = CCFN;
2225 }
2226
Santosh Shilimkar2263f022009-03-23 18:07:48 -07002227 if (cpu_class_is_omap2() && omap_dma_reserve_channels
2228 && (omap_dma_reserve_channels <= dma_lch_count))
2229 dma_lch_count = omap_dma_reserve_channels;
2230
Tony Lindgren4d963722008-07-03 12:24:31 +03002231 dma_chan = kzalloc(sizeof(struct omap_dma_lch) * dma_lch_count,
2232 GFP_KERNEL);
Tony Lindgren7e9bf842009-10-19 15:25:15 -07002233 if (!dma_chan) {
2234 r = -ENOMEM;
2235 goto out_unmap;
2236 }
Tony Lindgren4d963722008-07-03 12:24:31 +03002237
2238 if (cpu_class_is_omap2()) {
2239 dma_linked_lch = kzalloc(sizeof(struct dma_link_info) *
2240 dma_lch_count, GFP_KERNEL);
2241 if (!dma_linked_lch) {
Tony Lindgren7e9bf842009-10-19 15:25:15 -07002242 r = -ENOMEM;
2243 goto out_free;
Tony Lindgren4d963722008-07-03 12:24:31 +03002244 }
2245 }
2246
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002247 if (cpu_is_omap15xx()) {
2248 printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002249 dma_chan_count = 9;
2250 enable_1510_mode = 1;
Zebediah C. McClure557096f2009-03-23 18:07:44 -07002251 } else if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002252 printk(KERN_INFO "OMAP DMA hardware version %d\n",
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002253 dma_read(HW_ID, 0));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002254 printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002255 dma_read(CAPS_0, 0), dma_read(CAPS_1, 0),
2256 dma_read(CAPS_2, 0), dma_read(CAPS_3, 0),
2257 dma_read(CAPS_4, 0));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002258 if (!enable_1510_mode) {
2259 u16 w;
2260
2261 /* Disable OMAP 3.0/3.1 compatibility mode. */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002262 w = dma_read(GSCR, 0);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002263 w |= 1 << 3;
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002264 dma_write(w, GSCR, 0);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002265 dma_chan_count = 16;
2266 } else
2267 dma_chan_count = 9;
Anand Gadiyarf8151e52007-12-01 12:14:11 -08002268 } else if (cpu_class_is_omap2()) {
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002269 u8 revision = dma_read(REVISION, 0) & 0xff;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002270 printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
2271 revision >> 4, revision & 0xf);
Santosh Shilimkar2263f022009-03-23 18:07:48 -07002272 dma_chan_count = dma_lch_count;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002273 } else {
2274 dma_chan_count = 0;
2275 return 0;
2276 }
2277
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002278 spin_lock_init(&dma_chan_lock);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002279
2280 for (ch = 0; ch < dma_chan_count; ch++) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002281 omap_clear_dma(ch);
Mika Westerbergada8d4a2010-05-14 12:05:25 -07002282 if (cpu_class_is_omap2())
2283 omap2_disable_irq_lch(ch);
2284
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002285 dma_chan[ch].dev_id = -1;
2286 dma_chan[ch].next_lch = -1;
2287
2288 if (ch >= 6 && enable_1510_mode)
2289 continue;
2290
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002291 if (cpu_class_is_omap1()) {
Tony Lindgren97b7f712008-07-03 12:24:37 +03002292 /*
2293 * request_irq() doesn't like dev_id (ie. ch) being
2294 * zero, so we have to kludge around this.
2295 */
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002296 r = request_irq(omap1_dma_irq[ch],
2297 omap1_dma_irq_handler, 0, "DMA",
2298 (void *) (ch + 1));
2299 if (r != 0) {
2300 int i;
2301
2302 printk(KERN_ERR "unable to request IRQ %d "
2303 "for DMA (error %d)\n",
2304 omap1_dma_irq[ch], r);
2305 for (i = 0; i < ch; i++)
2306 free_irq(omap1_dma_irq[i],
2307 (void *) (i + 1));
Tony Lindgren7e9bf842009-10-19 15:25:15 -07002308 goto out_free;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002309 }
2310 }
2311 }
2312
Santosh Shilimkar44169072009-05-28 14:16:04 -07002313 if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx())
Anand Gadiyarf8151e52007-12-01 12:14:11 -08002314 omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE,
2315 DMA_DEFAULT_FIFO_DEPTH, 0);
2316
Santosh Shilimkar44169072009-05-28 14:16:04 -07002317 if (cpu_class_is_omap2()) {
2318 int irq;
2319 if (cpu_is_omap44xx())
Santosh Shilimkar5772ca72010-02-18 03:14:12 +05302320 irq = OMAP44XX_IRQ_SDMA_0;
Santosh Shilimkar44169072009-05-28 14:16:04 -07002321 else
2322 irq = INT_24XX_SDMA_IRQ0;
2323 setup_irq(irq, &omap24xx_dma_irq);
2324 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002325
Santosh Shilimkar1ce0f9d2010-02-18 08:59:08 +00002326 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Kalle Jokiniemiba50ea72009-03-26 15:59:00 +02002327 /* Enable smartidle idlemodes and autoidle */
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002328 u32 v = dma_read(OCP_SYSCONFIG, 0);
Kalle Jokiniemiaecedb92009-06-23 13:30:24 +03002329 v &= ~(DMA_SYSCONFIG_MIDLEMODE_MASK |
2330 DMA_SYSCONFIG_SIDLEMODE_MASK |
2331 DMA_SYSCONFIG_AUTOIDLE);
2332 v |= (DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_SMARTIDLE) |
2333 DMA_SYSCONFIG_SIDLEMODE(DMA_IDLEMODE_SMARTIDLE) |
2334 DMA_SYSCONFIG_AUTOIDLE);
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08002335 dma_write(v , OCP_SYSCONFIG, 0);
Kalle Jokiniemiba50ea72009-03-26 15:59:00 +02002336 /* reserve dma channels 0 and 1 in high security devices */
Santosh Shilimkar35c0dc32010-02-18 08:59:09 +00002337 if (cpu_is_omap34xx() &&
2338 (omap_type() != OMAP2_DEVICE_TYPE_GP)) {
Kalle Jokiniemiba50ea72009-03-26 15:59:00 +02002339 printk(KERN_INFO "Reserving DMA channels 0 and 1 for "
2340 "HS ROM code\n");
2341 dma_chan[0].dev_id = 0;
2342 dma_chan[1].dev_id = 1;
2343 }
Kalle Jokiniemiaecedb92009-06-23 13:30:24 +03002344 }
2345
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002346 return 0;
Tony Lindgren7e9bf842009-10-19 15:25:15 -07002347
2348out_free:
2349 kfree(dma_chan);
2350
2351out_unmap:
2352 iounmap(omap_dma_base);
2353
2354 return r;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002355}
2356
2357arch_initcall(omap_init_dma);
2358
Santosh Shilimkar2263f022009-03-23 18:07:48 -07002359/*
2360 * Reserve the omap SDMA channels using cmdline bootarg
2361 * "omap_dma_reserve_ch=". The valid range is 1 to 32
2362 */
2363static int __init omap_dma_cmdline_reserve_ch(char *str)
2364{
2365 if (get_option(&str, &omap_dma_reserve_channels) != 1)
2366 omap_dma_reserve_channels = 0;
2367 return 1;
2368}
2369
2370__setup("omap_dma_reserve_ch=", omap_dma_cmdline_reserve_ch);
2371
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002372