blob: 24770e5a5081d3704321757a94cc5456717db7b9 [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 *
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -080018 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
19 * Converted DMA library into DMA platform driver.
20 * - G, Manjunath Kondaiah <manjugk@ti.com>
21 *
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010022 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License version 2 as
24 * published by the Free Software Foundation.
25 *
26 */
27
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/sched.h>
31#include <linux/spinlock.h>
32#include <linux/errno.h>
33#include <linux/interrupt.h>
Thomas Gleixner418ca1f02006-07-01 22:32:41 +010034#include <linux/irq.h>
Tony Lindgren97b7f712008-07-03 12:24:37 +030035#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -070037#include <linux/delay.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010038
Tony Lindgren45c3eb72012-11-30 08:41:50 -080039#include <linux/omap-dma.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010040
Paul Walmsleybc4d8b52012-04-13 06:34:30 -060041/*
42 * MAX_LOGICAL_DMA_CH_COUNT: the maximum number of logical DMA
43 * channels that an instance of the SDMA IP block can support. Used
44 * to size arrays. (The actual maximum on a particular SoC may be less
45 * than this -- for example, OMAP1 SDMA instances only support 17 logical
46 * DMA channels.)
47 */
48#define MAX_LOGICAL_DMA_CH_COUNT 32
49
Anand Gadiyarf8151e52007-12-01 12:14:11 -080050#undef DEBUG
51
52#ifndef CONFIG_ARCH_OMAP1
53enum { DMA_CH_ALLOC_DONE, DMA_CH_PARAMS_SET_DONE, DMA_CH_STARTED,
54 DMA_CH_QUEUED, DMA_CH_NOTSTARTED, DMA_CH_PAUSED, DMA_CH_LINK_ENABLED
55};
56
57enum { DMA_CHAIN_STARTED, DMA_CHAIN_NOTSTARTED };
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000058#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010059
Tony Lindgren97b7f712008-07-03 12:24:37 +030060#define OMAP_DMA_ACTIVE 0x01
Adrian Hunter4fb699b2010-11-24 13:23:21 +020061#define OMAP2_DMA_CSR_CLEAR_MASK 0xffffffff
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010062
Tony Lindgren97b7f712008-07-03 12:24:37 +030063#define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010064
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -080065static struct omap_system_dma_plat_info *p;
66static struct omap_dma_dev_attr *d;
Tony Lindgren175655b2014-09-16 17:36:28 -070067static void omap_clear_dma(int lch);
68static int omap_dma_set_prio_lch(int lch, unsigned char read_prio,
69 unsigned char write_prio);
Tony Lindgren97b7f712008-07-03 12:24:37 +030070static int enable_1510_mode;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -080071static u32 errata;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010072
Tero Kristof2d11852008-08-28 13:13:31 +000073static struct omap_dma_global_context_registers {
74 u32 dma_irqenable_l0;
Tony Lindgren9ce24822014-05-16 14:05:35 -070075 u32 dma_irqenable_l1;
Tero Kristof2d11852008-08-28 13:13:31 +000076 u32 dma_ocp_sysconfig;
77 u32 dma_gcr;
78} omap_dma_global_context;
79
Anand Gadiyarf8151e52007-12-01 12:14:11 -080080struct dma_link_info {
81 int *linked_dmach_q;
82 int no_of_lchs_linked;
83
84 int q_count;
85 int q_tail;
86 int q_head;
87
88 int chain_state;
89 int chain_mode;
90
91};
92
Tony Lindgren4d963722008-07-03 12:24:31 +030093static struct dma_link_info *dma_linked_lch;
94
95#ifndef CONFIG_ARCH_OMAP1
Anand Gadiyarf8151e52007-12-01 12:14:11 -080096
97/* Chain handling macros */
98#define OMAP_DMA_CHAIN_QINIT(chain_id) \
99 do { \
100 dma_linked_lch[chain_id].q_head = \
101 dma_linked_lch[chain_id].q_tail = \
102 dma_linked_lch[chain_id].q_count = 0; \
103 } while (0)
104#define OMAP_DMA_CHAIN_QFULL(chain_id) \
105 (dma_linked_lch[chain_id].no_of_lchs_linked == \
106 dma_linked_lch[chain_id].q_count)
107#define OMAP_DMA_CHAIN_QLAST(chain_id) \
108 do { \
109 ((dma_linked_lch[chain_id].no_of_lchs_linked-1) == \
110 dma_linked_lch[chain_id].q_count) \
111 } while (0)
112#define OMAP_DMA_CHAIN_QEMPTY(chain_id) \
113 (0 == dma_linked_lch[chain_id].q_count)
114#define __OMAP_DMA_CHAIN_INCQ(end) \
115 ((end) = ((end)+1) % dma_linked_lch[chain_id].no_of_lchs_linked)
116#define OMAP_DMA_CHAIN_INCQHEAD(chain_id) \
117 do { \
118 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_head); \
119 dma_linked_lch[chain_id].q_count--; \
120 } while (0)
121
122#define OMAP_DMA_CHAIN_INCQTAIL(chain_id) \
123 do { \
124 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_tail); \
125 dma_linked_lch[chain_id].q_count++; \
126 } while (0)
127#endif
Tony Lindgren4d963722008-07-03 12:24:31 +0300128
129static int dma_lch_count;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100130static int dma_chan_count;
Santosh Shilimkar2263f022009-03-23 18:07:48 -0700131static int omap_dma_reserve_channels;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100132
133static spinlock_t dma_chan_lock;
Tony Lindgren4d963722008-07-03 12:24:31 +0300134static struct omap_dma_lch *dma_chan;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100135
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800136static inline void disable_lnk(int lch);
137static void omap_disable_channel_irq(int lch);
138static inline void omap_enable_channel_irq(int lch);
139
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000140#define REVISIT_24XX() printk(KERN_ERR "FIXME: no %s on 24xx\n", \
Harvey Harrison8e86f422008-03-04 15:08:02 -0800141 __func__);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000142
143#ifdef CONFIG_ARCH_OMAP15XX
144/* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */
Aaro Koskinenc7767582011-01-27 16:39:43 -0800145static int omap_dma_in_1510_mode(void)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000146{
147 return enable_1510_mode;
148}
149#else
150#define omap_dma_in_1510_mode() 0
151#endif
152
153#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100154static inline int get_gdma_dev(int req)
155{
156 u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
157 int shift = ((req - 1) % 5) * 6;
158
159 return ((omap_readl(reg) >> shift) & 0x3f) + 1;
160}
161
162static inline void set_gdma_dev(int req, int dev)
163{
164 u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
165 int shift = ((req - 1) % 5) * 6;
166 u32 l;
167
168 l = omap_readl(reg);
169 l &= ~(0x3f << shift);
170 l |= (dev - 1) << shift;
171 omap_writel(l, reg);
172}
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000173#else
174#define set_gdma_dev(req, dev) do {} while (0)
Tony Lindgren2c799ce2012-02-24 10:34:35 -0800175#define omap_readl(reg) 0
176#define omap_writel(val, reg) do {} while (0)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000177#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100178
Tony Lindgren54b693d2012-10-02 13:39:28 -0700179#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300180void omap_set_dma_priority(int lch, int dst_port, int priority)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100181{
182 unsigned long reg;
183 u32 l;
184
Tony Lindgren82809602012-10-30 11:03:22 -0700185 if (dma_omap1()) {
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300186 switch (dst_port) {
187 case OMAP_DMA_PORT_OCP_T1: /* FFFECC00 */
188 reg = OMAP_TC_OCPT1_PRIOR;
189 break;
190 case OMAP_DMA_PORT_OCP_T2: /* FFFECCD0 */
191 reg = OMAP_TC_OCPT2_PRIOR;
192 break;
193 case OMAP_DMA_PORT_EMIFF: /* FFFECC08 */
194 reg = OMAP_TC_EMIFF_PRIOR;
195 break;
196 case OMAP_DMA_PORT_EMIFS: /* FFFECC04 */
197 reg = OMAP_TC_EMIFS_PRIOR;
198 break;
199 default:
200 BUG();
201 return;
202 }
203 l = omap_readl(reg);
204 l &= ~(0xf << 8);
205 l |= (priority & 0xf) << 8;
206 omap_writel(l, reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100207 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100208}
Tony Lindgren54b693d2012-10-02 13:39:28 -0700209#endif
210
211#ifdef CONFIG_ARCH_OMAP2PLUS
212void omap_set_dma_priority(int lch, int dst_port, int priority)
213{
214 u32 ccr;
215
216 ccr = p->dma_read(CCR, lch);
217 if (priority)
218 ccr |= (1 << 6);
219 else
220 ccr &= ~(1 << 6);
221 p->dma_write(ccr, CCR, lch);
222}
223#endif
Tony Lindgren97b7f712008-07-03 12:24:37 +0300224EXPORT_SYMBOL(omap_set_dma_priority);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100225
226void omap_set_dma_transfer_params(int lch, int data_type, int elem_count,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000227 int frame_count, int sync_mode,
228 int dma_trigger, int src_or_dst_synch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100229{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300230 u32 l;
231
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800232 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300233 l &= ~0x03;
234 l |= data_type;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800235 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100236
Tony Lindgren82809602012-10-30 11:03:22 -0700237 if (dma_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300238 u16 ccr;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100239
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800240 ccr = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300241 ccr &= ~(1 << 5);
242 if (sync_mode == OMAP_DMA_SYNC_FRAME)
243 ccr |= 1 << 5;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800244 p->dma_write(ccr, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300245
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800246 ccr = p->dma_read(CCR2, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300247 ccr &= ~(1 << 2);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000248 if (sync_mode == OMAP_DMA_SYNC_BLOCK)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300249 ccr |= 1 << 2;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800250 p->dma_write(ccr, CCR2, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000251 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100252
Tony Lindgren82809602012-10-30 11:03:22 -0700253 if (dma_omap2plus() && dma_trigger) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300254 u32 val;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100255
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800256 val = p->dma_read(CCR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100257
Anand Gadiyar4b3cf442009-01-15 13:09:53 +0200258 /* DMA_SYNCHRO_CONTROL_UPPER depends on the channel number */
Samu Onkalo72a11792010-08-02 14:21:40 +0300259 val &= ~((1 << 23) | (3 << 19) | 0x1f);
Anand Gadiyar4b3cf442009-01-15 13:09:53 +0200260 val |= (dma_trigger & ~0x1f) << 14;
261 val |= dma_trigger & 0x1f;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000262
263 if (sync_mode & OMAP_DMA_SYNC_FRAME)
264 val |= 1 << 5;
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700265 else
266 val &= ~(1 << 5);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000267
268 if (sync_mode & OMAP_DMA_SYNC_BLOCK)
269 val |= 1 << 18;
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700270 else
271 val &= ~(1 << 18);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000272
Samu Onkalo72a11792010-08-02 14:21:40 +0300273 if (src_or_dst_synch == OMAP_DMA_DST_SYNC_PREFETCH) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000274 val &= ~(1 << 24); /* dest synch */
Samu Onkalo72a11792010-08-02 14:21:40 +0300275 val |= (1 << 23); /* Prefetch */
276 } else if (src_or_dst_synch) {
277 val |= 1 << 24; /* source synch */
278 } else {
279 val &= ~(1 << 24); /* dest synch */
280 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800281 p->dma_write(val, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000282 }
283
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800284 p->dma_write(elem_count, CEN, lch);
285 p->dma_write(frame_count, CFN, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100286}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300287EXPORT_SYMBOL(omap_set_dma_transfer_params);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000288
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300289void omap_set_dma_write_mode(int lch, enum omap_dma_write_mode mode)
290{
Tony Lindgren82809602012-10-30 11:03:22 -0700291 if (dma_omap2plus()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300292 u32 csdp;
293
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800294 csdp = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300295 csdp &= ~(0x3 << 16);
296 csdp |= (mode << 16);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800297 p->dma_write(csdp, CSDP, lch);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300298 }
299}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300300EXPORT_SYMBOL(omap_set_dma_write_mode);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300301
Tony Lindgren0499bde2008-07-03 12:24:36 +0300302void omap_set_dma_channel_mode(int lch, enum omap_dma_channel_mode mode)
303{
Tony Lindgren82809602012-10-30 11:03:22 -0700304 if (dma_omap1() && !dma_omap15xx()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300305 u32 l;
306
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800307 l = p->dma_read(LCH_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300308 l &= ~0x7;
309 l |= mode;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800310 p->dma_write(l, LCH_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300311 }
312}
313EXPORT_SYMBOL(omap_set_dma_channel_mode);
314
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000315/* Note that src_port is only for omap1 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100316void omap_set_dma_src_params(int lch, int src_port, int src_amode,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000317 unsigned long src_start,
318 int src_ei, int src_fi)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100319{
Tony Lindgren97b7f712008-07-03 12:24:37 +0300320 u32 l;
321
Tony Lindgren82809602012-10-30 11:03:22 -0700322 if (dma_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300323 u16 w;
324
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800325 w = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300326 w &= ~(0x1f << 2);
327 w |= src_port << 2;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800328 p->dma_write(w, CSDP, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300329 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300330
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800331 l = p->dma_read(CCR, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300332 l &= ~(0x03 << 12);
333 l |= src_amode << 12;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800334 p->dma_write(l, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300335
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800336 p->dma_write(src_start, CSSA, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100337
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800338 p->dma_write(src_ei, CSEI, lch);
339 p->dma_write(src_fi, CSFI, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300340}
341EXPORT_SYMBOL(omap_set_dma_src_params);
342
343void omap_set_dma_params(int lch, struct omap_dma_channel_params *params)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000344{
345 omap_set_dma_transfer_params(lch, params->data_type,
346 params->elem_count, params->frame_count,
347 params->sync_mode, params->trigger,
348 params->src_or_dst_synch);
349 omap_set_dma_src_params(lch, params->src_port,
350 params->src_amode, params->src_start,
351 params->src_ei, params->src_fi);
352
353 omap_set_dma_dest_params(lch, params->dst_port,
354 params->dst_amode, params->dst_start,
355 params->dst_ei, params->dst_fi);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800356 if (params->read_prio || params->write_prio)
357 omap_dma_set_prio_lch(lch, params->read_prio,
358 params->write_prio);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100359}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300360EXPORT_SYMBOL(omap_set_dma_params);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100361
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100362void omap_set_dma_src_data_pack(int lch, int enable)
363{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300364 u32 l;
365
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800366 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300367 l &= ~(1 << 6);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000368 if (enable)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300369 l |= (1 << 6);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800370 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100371}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300372EXPORT_SYMBOL(omap_set_dma_src_data_pack);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100373
374void omap_set_dma_src_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
375{
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700376 unsigned int burst = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300377 u32 l;
378
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800379 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300380 l &= ~(0x03 << 7);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100381
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100382 switch (burst_mode) {
383 case OMAP_DMA_DATA_BURST_DIS:
384 break;
385 case OMAP_DMA_DATA_BURST_4:
Tony Lindgren82809602012-10-30 11:03:22 -0700386 if (dma_omap2plus())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700387 burst = 0x1;
388 else
389 burst = 0x2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100390 break;
391 case OMAP_DMA_DATA_BURST_8:
Tony Lindgren82809602012-10-30 11:03:22 -0700392 if (dma_omap2plus()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700393 burst = 0x2;
394 break;
395 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700396 /*
397 * not supported by current hardware on OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100398 * w |= (0x03 << 7);
399 * fall through
400 */
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700401 case OMAP_DMA_DATA_BURST_16:
Tony Lindgren82809602012-10-30 11:03:22 -0700402 if (dma_omap2plus()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700403 burst = 0x3;
404 break;
405 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700406 /*
407 * OMAP1 don't support burst 16
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700408 * fall through
409 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100410 default:
411 BUG();
412 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300413
414 l |= (burst << 7);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800415 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100416}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300417EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100418
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000419/* Note that dest_port is only for OMAP1 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100420void omap_set_dma_dest_params(int lch, int dest_port, int dest_amode,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000421 unsigned long dest_start,
422 int dst_ei, int dst_fi)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100423{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300424 u32 l;
425
Tony Lindgren82809602012-10-30 11:03:22 -0700426 if (dma_omap1()) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800427 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300428 l &= ~(0x1f << 9);
429 l |= dest_port << 9;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800430 p->dma_write(l, CSDP, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000431 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100432
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800433 l = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300434 l &= ~(0x03 << 14);
435 l |= dest_amode << 14;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800436 p->dma_write(l, CCR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100437
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800438 p->dma_write(dest_start, CDSA, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100439
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800440 p->dma_write(dst_ei, CDEI, lch);
441 p->dma_write(dst_fi, CDFI, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100442}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300443EXPORT_SYMBOL(omap_set_dma_dest_params);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100444
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100445void omap_set_dma_dest_data_pack(int lch, int enable)
446{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300447 u32 l;
448
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800449 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300450 l &= ~(1 << 13);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000451 if (enable)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300452 l |= 1 << 13;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800453 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100454}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300455EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100456
457void omap_set_dma_dest_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
458{
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700459 unsigned int burst = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300460 u32 l;
461
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800462 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300463 l &= ~(0x03 << 14);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100464
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100465 switch (burst_mode) {
466 case OMAP_DMA_DATA_BURST_DIS:
467 break;
468 case OMAP_DMA_DATA_BURST_4:
Tony Lindgren82809602012-10-30 11:03:22 -0700469 if (dma_omap2plus())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700470 burst = 0x1;
471 else
472 burst = 0x2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100473 break;
474 case OMAP_DMA_DATA_BURST_8:
Tony Lindgren82809602012-10-30 11:03:22 -0700475 if (dma_omap2plus())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700476 burst = 0x2;
477 else
478 burst = 0x3;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100479 break;
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700480 case OMAP_DMA_DATA_BURST_16:
Tony Lindgren82809602012-10-30 11:03:22 -0700481 if (dma_omap2plus()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700482 burst = 0x3;
483 break;
484 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700485 /*
486 * OMAP1 don't support burst 16
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700487 * fall through
488 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100489 default:
490 printk(KERN_ERR "Invalid DMA burst mode\n");
491 BUG();
492 return;
493 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300494 l |= (burst << 14);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800495 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100496}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300497EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100498
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000499static inline void omap_enable_channel_irq(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100500{
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700501 /* Clear CSR */
Tony Lindgren82809602012-10-30 11:03:22 -0700502 if (dma_omap1())
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700503 p->dma_read(CSR, lch);
504 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800505 p->dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000506
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100507 /* Enable some nice interrupts. */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800508 p->dma_write(dma_chan[lch].enabled_irqs, CICR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100509}
510
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700511static inline void omap_disable_channel_irq(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100512{
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700513 /* disable channel interrupts */
514 p->dma_write(0, CICR, lch);
515 /* Clear CSR */
Tony Lindgren82809602012-10-30 11:03:22 -0700516 if (dma_omap1())
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700517 p->dma_read(CSR, lch);
518 else
519 p->dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100520}
521
522void omap_enable_dma_irq(int lch, u16 bits)
523{
524 dma_chan[lch].enabled_irqs |= bits;
525}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300526EXPORT_SYMBOL(omap_enable_dma_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100527
528void omap_disable_dma_irq(int lch, u16 bits)
529{
530 dma_chan[lch].enabled_irqs &= ~bits;
531}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300532EXPORT_SYMBOL(omap_disable_dma_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100533
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000534static inline void enable_lnk(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100535{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300536 u32 l;
537
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800538 l = p->dma_read(CLNK_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300539
Tony Lindgren82809602012-10-30 11:03:22 -0700540 if (dma_omap1())
Tony Lindgren0499bde2008-07-03 12:24:36 +0300541 l &= ~(1 << 14);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100542
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000543 /* Set the ENABLE_LNK bits */
544 if (dma_chan[lch].next_lch != -1)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300545 l = dma_chan[lch].next_lch | (1 << 15);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800546
547#ifndef CONFIG_ARCH_OMAP1
Tony Lindgren82809602012-10-30 11:03:22 -0700548 if (dma_omap2plus())
Tony Lindgren97b7f712008-07-03 12:24:37 +0300549 if (dma_chan[lch].next_linked_ch != -1)
550 l = dma_chan[lch].next_linked_ch | (1 << 15);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800551#endif
Tony Lindgren0499bde2008-07-03 12:24:36 +0300552
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800553 p->dma_write(l, CLNK_CTRL, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100554}
555
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000556static inline void disable_lnk(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100557{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300558 u32 l;
559
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800560 l = p->dma_read(CLNK_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300561
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000562 /* Disable interrupts */
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700563 omap_disable_channel_irq(lch);
564
Tony Lindgren82809602012-10-30 11:03:22 -0700565 if (dma_omap1()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000566 /* Set the STOP_LNK bit */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300567 l |= 1 << 14;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100568 }
569
Tony Lindgren82809602012-10-30 11:03:22 -0700570 if (dma_omap2plus()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000571 /* Clear the ENABLE_LNK bit */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300572 l &= ~(1 << 15);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000573 }
574
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800575 p->dma_write(l, CLNK_CTRL, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000576 dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
577}
578
579static inline void omap2_enable_irq_lch(int lch)
580{
581 u32 val;
Tao Huee907322009-11-10 18:55:17 -0800582 unsigned long flags;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000583
Tony Lindgren82809602012-10-30 11:03:22 -0700584 if (dma_omap1())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000585 return;
586
Tao Huee907322009-11-10 18:55:17 -0800587 spin_lock_irqsave(&dma_chan_lock, flags);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700588 /* clear IRQ STATUS */
589 p->dma_write(1 << lch, IRQSTATUS_L0, lch);
590 /* Enable interrupt */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800591 val = p->dma_read(IRQENABLE_L0, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000592 val |= 1 << lch;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800593 p->dma_write(val, IRQENABLE_L0, lch);
Tao Huee907322009-11-10 18:55:17 -0800594 spin_unlock_irqrestore(&dma_chan_lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100595}
596
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700597static inline void omap2_disable_irq_lch(int lch)
598{
599 u32 val;
600 unsigned long flags;
601
Tony Lindgren82809602012-10-30 11:03:22 -0700602 if (dma_omap1())
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700603 return;
604
605 spin_lock_irqsave(&dma_chan_lock, flags);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700606 /* Disable interrupt */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800607 val = p->dma_read(IRQENABLE_L0, lch);
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700608 val &= ~(1 << lch);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800609 p->dma_write(val, IRQENABLE_L0, lch);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700610 /* clear IRQ STATUS */
611 p->dma_write(1 << lch, IRQSTATUS_L0, lch);
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700612 spin_unlock_irqrestore(&dma_chan_lock, flags);
613}
614
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100615int omap_request_dma(int dev_id, const char *dev_name,
Tony Lindgren97b7f712008-07-03 12:24:37 +0300616 void (*callback)(int lch, u16 ch_status, void *data),
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100617 void *data, int *dma_ch_out)
618{
619 int ch, free_ch = -1;
620 unsigned long flags;
621 struct omap_dma_lch *chan;
622
Russell King5c65c362014-06-07 10:47:36 +0100623 WARN(strcmp(dev_name, "DMA engine"), "Using deprecated platform DMA API - please update to DMA engine");
624
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100625 spin_lock_irqsave(&dma_chan_lock, flags);
626 for (ch = 0; ch < dma_chan_count; ch++) {
627 if (free_ch == -1 && dma_chan[ch].dev_id == -1) {
628 free_ch = ch;
R Sricharan03a6d4a2013-06-13 19:47:09 +0530629 /* Exit after first free channel found */
630 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100631 }
632 }
633 if (free_ch == -1) {
634 spin_unlock_irqrestore(&dma_chan_lock, flags);
635 return -EBUSY;
636 }
637 chan = dma_chan + free_ch;
638 chan->dev_id = dev_id;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000639
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800640 if (p->clear_lch_regs)
641 p->clear_lch_regs(free_ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000642
Tony Lindgren82809602012-10-30 11:03:22 -0700643 if (dma_omap2plus())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000644 omap_clear_dma(free_ch);
645
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100646 spin_unlock_irqrestore(&dma_chan_lock, flags);
647
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100648 chan->dev_name = dev_name;
649 chan->callback = callback;
650 chan->data = data;
Jarkko Nikulaa92fda12009-01-29 08:57:12 -0800651 chan->flags = 0;
Tony Lindgren97b7f712008-07-03 12:24:37 +0300652
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800653#ifndef CONFIG_ARCH_OMAP1
Tony Lindgren82809602012-10-30 11:03:22 -0700654 if (dma_omap2plus()) {
Tony Lindgren97b7f712008-07-03 12:24:37 +0300655 chan->chain_id = -1;
656 chan->next_linked_ch = -1;
657 }
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800658#endif
Tony Lindgren97b7f712008-07-03 12:24:37 +0300659
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700660 chan->enabled_irqs = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000661
Tony Lindgren82809602012-10-30 11:03:22 -0700662 if (dma_omap1())
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700663 chan->enabled_irqs |= OMAP1_DMA_TOUT_IRQ;
Tony Lindgren82809602012-10-30 11:03:22 -0700664 else if (dma_omap2plus())
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700665 chan->enabled_irqs |= OMAP2_DMA_MISALIGNED_ERR_IRQ |
666 OMAP2_DMA_TRANS_ERR_IRQ;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100667
Tony Lindgren82809602012-10-30 11:03:22 -0700668 if (dma_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100669 /* If the sync device is set, configure it dynamically. */
670 if (dev_id != 0) {
671 set_gdma_dev(free_ch + 1, dev_id);
672 dev_id = free_ch + 1;
673 }
Tony Lindgren97b7f712008-07-03 12:24:37 +0300674 /*
675 * Disable the 1510 compatibility mode and set the sync device
676 * id.
677 */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800678 p->dma_write(dev_id | (1 << 10), CCR, free_ch);
Tony Lindgren82809602012-10-30 11:03:22 -0700679 } else if (dma_omap1()) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800680 p->dma_write(dev_id, CCR, free_ch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100681 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000682
Tony Lindgren82809602012-10-30 11:03:22 -0700683 if (dma_omap2plus()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000684 omap_enable_channel_irq(free_ch);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700685 omap2_enable_irq_lch(free_ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000686 }
687
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100688 *dma_ch_out = free_ch;
689
690 return 0;
691}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300692EXPORT_SYMBOL(omap_request_dma);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100693
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000694void omap_free_dma(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100695{
696 unsigned long flags;
697
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000698 if (dma_chan[lch].dev_id == -1) {
Tony Lindgren97b7f712008-07-03 12:24:37 +0300699 pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000700 lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100701 return;
702 }
Tony Lindgren97b7f712008-07-03 12:24:37 +0300703
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700704 /* Disable interrupt for logical channel */
Tony Lindgren82809602012-10-30 11:03:22 -0700705 if (dma_omap2plus())
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700706 omap2_disable_irq_lch(lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000707
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700708 /* Disable all DMA interrupts for the channel. */
709 omap_disable_channel_irq(lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000710
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700711 /* Make sure the DMA transfer is stopped. */
712 p->dma_write(0, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000713
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700714 /* Clear registers */
Tony Lindgren82809602012-10-30 11:03:22 -0700715 if (dma_omap2plus())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000716 omap_clear_dma(lch);
Santosh Shilimkarda1b94e2009-04-23 11:10:40 -0700717
718 spin_lock_irqsave(&dma_chan_lock, flags);
719 dma_chan[lch].dev_id = -1;
720 dma_chan[lch].next_lch = -1;
721 dma_chan[lch].callback = NULL;
722 spin_unlock_irqrestore(&dma_chan_lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100723}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300724EXPORT_SYMBOL(omap_free_dma);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100725
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800726/**
727 * @brief omap_dma_set_global_params : Set global priority settings for dma
728 *
729 * @param arb_rate
730 * @param max_fifo_depth
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700731 * @param tparams - Number of threads to reserve : DMA_THREAD_RESERVE_NORM
732 * DMA_THREAD_RESERVE_ONET
733 * DMA_THREAD_RESERVE_TWOT
734 * DMA_THREAD_RESERVE_THREET
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800735 */
736void
737omap_dma_set_global_params(int arb_rate, int max_fifo_depth, int tparams)
738{
739 u32 reg;
740
Tony Lindgren82809602012-10-30 11:03:22 -0700741 if (dma_omap1()) {
Harvey Harrison8e86f422008-03-04 15:08:02 -0800742 printk(KERN_ERR "FIXME: no %s on 15xx/16xx\n", __func__);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800743 return;
744 }
745
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700746 if (max_fifo_depth == 0)
747 max_fifo_depth = 1;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800748 if (arb_rate == 0)
749 arb_rate = 1;
750
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700751 reg = 0xff & max_fifo_depth;
752 reg |= (0x3 & tparams) << 12;
753 reg |= (arb_rate & 0xff) << 16;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800754
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800755 p->dma_write(reg, GCR, 0);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800756}
757EXPORT_SYMBOL(omap_dma_set_global_params);
758
759/**
760 * @brief omap_dma_set_prio_lch : Set channel wise priority settings
761 *
762 * @param lch
763 * @param read_prio - Read priority
764 * @param write_prio - Write priority
765 * Both of the above can be set with one of the following values :
766 * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW
767 */
Tony Lindgren175655b2014-09-16 17:36:28 -0700768static int
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800769omap_dma_set_prio_lch(int lch, unsigned char read_prio,
770 unsigned char write_prio)
771{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300772 u32 l;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800773
Tony Lindgren4d963722008-07-03 12:24:31 +0300774 if (unlikely((lch < 0 || lch >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800775 printk(KERN_ERR "Invalid channel id\n");
776 return -EINVAL;
777 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800778 l = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300779 l &= ~((1 << 6) | (1 << 26));
Tony Lindgren82809602012-10-30 11:03:22 -0700780 if (d->dev_caps & IS_RW_PRIORITY)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300781 l |= ((read_prio & 0x1) << 6) | ((write_prio & 0x1) << 26);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800782 else
Tony Lindgren0499bde2008-07-03 12:24:36 +0300783 l |= ((read_prio & 0x1) << 6);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800784
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800785 p->dma_write(l, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300786
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800787 return 0;
788}
Tony Lindgren175655b2014-09-16 17:36:28 -0700789
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800790
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000791/*
792 * Clears any DMA state so the DMA engine is ready to restart with new buffers
793 * through omap_start_dma(). Any buffers in flight are discarded.
794 */
Tony Lindgren175655b2014-09-16 17:36:28 -0700795static void omap_clear_dma(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100796{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000797 unsigned long flags;
798
799 local_irq_save(flags);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800800 p->clear_dma(lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000801 local_irq_restore(flags);
802}
803
804void omap_start_dma(int lch)
805{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300806 u32 l;
807
manjugk manjugk519e6162010-03-04 07:11:56 +0000808 /*
809 * The CPC/CDAC register needs to be initialized to zero
810 * before starting dma transfer.
811 */
Tony Lindgren82809602012-10-30 11:03:22 -0700812 if (dma_omap15xx())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800813 p->dma_write(0, CPC, lch);
manjugk manjugk519e6162010-03-04 07:11:56 +0000814 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800815 p->dma_write(0, CDAC, lch);
manjugk manjugk519e6162010-03-04 07:11:56 +0000816
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000817 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
818 int next_lch, cur_lch;
Paul Walmsleybc4d8b52012-04-13 06:34:30 -0600819 char dma_chan_link_map[MAX_LOGICAL_DMA_CH_COUNT];
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000820
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000821 /* Set the link register of the first channel */
822 enable_lnk(lch);
823
824 memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
R Sricharanf0a3ff22013-06-13 19:47:10 +0530825 dma_chan_link_map[lch] = 1;
826
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000827 cur_lch = dma_chan[lch].next_lch;
828 do {
829 next_lch = dma_chan[cur_lch].next_lch;
830
831 /* The loop case: we've been here already */
832 if (dma_chan_link_map[cur_lch])
833 break;
834 /* Mark the current channel */
835 dma_chan_link_map[cur_lch] = 1;
836
837 enable_lnk(cur_lch);
838 omap_enable_channel_irq(cur_lch);
839
840 cur_lch = next_lch;
841 } while (next_lch != -1);
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800842 } else if (IS_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS))
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800843 p->dma_write(lch, CLNK_CTRL, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000844
845 omap_enable_channel_irq(lch);
846
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800847 l = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300848
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800849 if (IS_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING))
850 l |= OMAP_DMA_CCR_BUFFERING_DISABLE;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300851 l |= OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800852
Russell King35453582012-04-14 18:57:10 +0100853 /*
854 * As dma_write() uses IO accessors which are weakly ordered, there
855 * is no guarantee that data in coherent DMA memory will be visible
856 * to the DMA device. Add a memory barrier here to ensure that any
857 * such data is visible prior to enabling DMA.
858 */
859 mb();
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800860 p->dma_write(l, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000861
862 dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
863}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300864EXPORT_SYMBOL(omap_start_dma);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000865
866void omap_stop_dma(int lch)
867{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300868 u32 l;
869
Santosh Shilimkar9da65a92009-10-22 14:46:31 -0700870 /* Disable all interrupts on the channel */
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700871 omap_disable_channel_irq(lch);
Santosh Shilimkar9da65a92009-10-22 14:46:31 -0700872
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800873 l = p->dma_read(CCR, lch);
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800874 if (IS_DMA_ERRATA(DMA_ERRATA_i541) &&
875 (l & OMAP_DMA_CCR_SEL_SRC_DST_SYNC)) {
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700876 int i = 0;
877 u32 sys_cf;
878
879 /* Configure No-Standby */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800880 l = p->dma_read(OCP_SYSCONFIG, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700881 sys_cf = l;
882 l &= ~DMA_SYSCONFIG_MIDLEMODE_MASK;
883 l |= DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_NO_IDLE);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800884 p->dma_write(l , OCP_SYSCONFIG, 0);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700885
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800886 l = p->dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700887 l &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800888 p->dma_write(l, CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700889
890 /* Wait for sDMA FIFO drain */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800891 l = p->dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700892 while (i < 100 && (l & (OMAP_DMA_CCR_RD_ACTIVE |
893 OMAP_DMA_CCR_WR_ACTIVE))) {
894 udelay(5);
895 i++;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800896 l = p->dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700897 }
898 if (i >= 100)
Paul Walmsley7852ec02012-07-26 00:54:26 -0600899 pr_err("DMA drain did not complete on lch %d\n", lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700900 /* Restore OCP_SYSCONFIG */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800901 p->dma_write(sys_cf, OCP_SYSCONFIG, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700902 } else {
903 l &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800904 p->dma_write(l, CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700905 }
Santosh Shilimkar9da65a92009-10-22 14:46:31 -0700906
Russell King35453582012-04-14 18:57:10 +0100907 /*
908 * Ensure that data transferred by DMA is visible to any access
909 * after DMA has been disabled. This is important for coherent
910 * DMA regions.
911 */
912 mb();
913
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000914 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
915 int next_lch, cur_lch = lch;
Paul Walmsleybc4d8b52012-04-13 06:34:30 -0600916 char dma_chan_link_map[MAX_LOGICAL_DMA_CH_COUNT];
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000917
918 memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
919 do {
920 /* The loop case: we've been here already */
921 if (dma_chan_link_map[cur_lch])
922 break;
923 /* Mark the current channel */
924 dma_chan_link_map[cur_lch] = 1;
925
926 disable_lnk(cur_lch);
927
928 next_lch = dma_chan[cur_lch].next_lch;
929 cur_lch = next_lch;
930 } while (next_lch != -1);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000931 }
932
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000933 dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
934}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300935EXPORT_SYMBOL(omap_stop_dma);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000936
937/*
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300938 * Allows changing the DMA callback function or data. This may be needed if
939 * the driver shares a single DMA channel for multiple dma triggers.
940 */
941int omap_set_dma_callback(int lch,
Tony Lindgren97b7f712008-07-03 12:24:37 +0300942 void (*callback)(int lch, u16 ch_status, void *data),
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300943 void *data)
944{
945 unsigned long flags;
946
947 if (lch < 0)
948 return -ENODEV;
949
950 spin_lock_irqsave(&dma_chan_lock, flags);
951 if (dma_chan[lch].dev_id == -1) {
952 printk(KERN_ERR "DMA callback for not set for free channel\n");
953 spin_unlock_irqrestore(&dma_chan_lock, flags);
954 return -EINVAL;
955 }
956 dma_chan[lch].callback = callback;
957 dma_chan[lch].data = data;
958 spin_unlock_irqrestore(&dma_chan_lock, flags);
959
960 return 0;
961}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300962EXPORT_SYMBOL(omap_set_dma_callback);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300963
964/*
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000965 * Returns current physical source address for the given DMA channel.
966 * If the channel is running the caller must disable interrupts prior calling
967 * this function and process the returned value before re-enabling interrupt to
968 * prevent races with the interrupt handler. Note that in continuous mode there
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300969 * is a chance for CSSA_L register overflow between the two reads resulting
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000970 * in incorrect return value.
971 */
972dma_addr_t omap_get_dma_src_pos(int lch)
973{
Tony Lindgren0695de32007-05-07 18:24:14 -0700974 dma_addr_t offset = 0;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000975
Tony Lindgren82809602012-10-30 11:03:22 -0700976 if (dma_omap15xx())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800977 offset = p->dma_read(CPC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300978 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800979 offset = p->dma_read(CSAC, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000980
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800981 if (IS_DMA_ERRATA(DMA_ERRATA_3_3) && offset == 0)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800982 offset = p->dma_read(CSAC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300983
Tony Lindgren82809602012-10-30 11:03:22 -0700984 if (!dma_omap15xx()) {
Peter Ujfalusi7ba96682011-12-09 13:38:00 -0800985 /*
986 * CDAC == 0 indicates that the DMA transfer on the channel has
987 * not been started (no data has been transferred so far).
988 * Return the programmed source start address in this case.
989 */
990 if (likely(p->dma_read(CDAC, lch)))
991 offset = p->dma_read(CSAC, lch);
992 else
993 offset = p->dma_read(CSSA, lch);
994 }
995
Tony Lindgren82809602012-10-30 11:03:22 -0700996 if (dma_omap1())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800997 offset |= (p->dma_read(CSSA, lch) & 0xFFFF0000);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000998
999 return offset;
1000}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001001EXPORT_SYMBOL(omap_get_dma_src_pos);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001002
1003/*
1004 * Returns current physical destination address for the given DMA channel.
1005 * If the channel is running the caller must disable interrupts prior calling
1006 * this function and process the returned value before re-enabling interrupt to
1007 * prevent races with the interrupt handler. Note that in continuous mode there
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001008 * is a chance for CDSA_L register overflow between the two reads resulting
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001009 * in incorrect return value.
1010 */
1011dma_addr_t omap_get_dma_dst_pos(int lch)
1012{
Tony Lindgren0695de32007-05-07 18:24:14 -07001013 dma_addr_t offset = 0;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001014
Tony Lindgren82809602012-10-30 11:03:22 -07001015 if (dma_omap15xx())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001016 offset = p->dma_read(CPC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001017 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001018 offset = p->dma_read(CDAC, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001019
Tony Lindgren0499bde2008-07-03 12:24:36 +03001020 /*
1021 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1022 * read before the DMA controller finished disabling the channel.
1023 */
Tony Lindgren82809602012-10-30 11:03:22 -07001024 if (!dma_omap15xx() && offset == 0) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001025 offset = p->dma_read(CDAC, lch);
Peter Ujfalusi06e80772011-12-09 13:38:00 -08001026 /*
1027 * CDAC == 0 indicates that the DMA transfer on the channel has
1028 * not been started (no data has been transferred so far).
1029 * Return the programmed destination start address in this case.
1030 */
1031 if (unlikely(!offset))
1032 offset = p->dma_read(CDSA, lch);
1033 }
Tony Lindgren0499bde2008-07-03 12:24:36 +03001034
Tony Lindgren82809602012-10-30 11:03:22 -07001035 if (dma_omap1())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001036 offset |= (p->dma_read(CDSA, lch) & 0xFFFF0000);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001037
1038 return offset;
1039}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001040EXPORT_SYMBOL(omap_get_dma_dst_pos);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001041
Tony Lindgren0499bde2008-07-03 12:24:36 +03001042int omap_get_dma_active_status(int lch)
1043{
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001044 return (p->dma_read(CCR, lch) & OMAP_DMA_CCR_EN) != 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001045}
1046EXPORT_SYMBOL(omap_get_dma_active_status);
1047
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001048int omap_dma_running(void)
1049{
1050 int lch;
1051
Tony Lindgren82809602012-10-30 11:03:22 -07001052 if (dma_omap1())
Janusz Krzysztofikf8e9e982009-12-11 16:16:33 -08001053 if (omap_lcd_dma_running())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001054 return 1;
1055
1056 for (lch = 0; lch < dma_chan_count; lch++)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001057 if (p->dma_read(CCR, lch) & OMAP_DMA_CCR_EN)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001058 return 1;
1059
1060 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001061}
1062
1063/*
1064 * lch_queue DMA will start right after lch_head one is finished.
1065 * For this DMA link to start, you still need to start (see omap_start_dma)
1066 * the first one. That will fire up the entire queue.
1067 */
Tony Lindgren97b7f712008-07-03 12:24:37 +03001068void omap_dma_link_lch(int lch_head, int lch_queue)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001069{
1070 if (omap_dma_in_1510_mode()) {
Janusz Krzysztofik9f0f4ae2009-08-23 17:56:12 +02001071 if (lch_head == lch_queue) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001072 p->dma_write(p->dma_read(CCR, lch_head) | (3 << 8),
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001073 CCR, lch_head);
Janusz Krzysztofik9f0f4ae2009-08-23 17:56:12 +02001074 return;
1075 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001076 printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
1077 BUG();
1078 return;
1079 }
1080
1081 if ((dma_chan[lch_head].dev_id == -1) ||
1082 (dma_chan[lch_queue].dev_id == -1)) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001083 pr_err("omap_dma: trying to link non requested channels\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001084 dump_stack();
1085 }
1086
1087 dma_chan[lch_head].next_lch = lch_queue;
1088}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001089EXPORT_SYMBOL(omap_dma_link_lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001090
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001091/*----------------------------------------------------------------------------*/
1092
1093#ifdef CONFIG_ARCH_OMAP1
1094
1095static int omap1_dma_handle_ch(int ch)
1096{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001097 u32 csr;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001098
1099 if (enable_1510_mode && ch >= 6) {
1100 csr = dma_chan[ch].saved_csr;
1101 dma_chan[ch].saved_csr = 0;
1102 } else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001103 csr = p->dma_read(CSR, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001104 if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) {
1105 dma_chan[ch + 6].saved_csr = csr >> 7;
1106 csr &= 0x7f;
1107 }
1108 if ((csr & 0x3f) == 0)
1109 return 0;
1110 if (unlikely(dma_chan[ch].dev_id == -1)) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001111 pr_warn("Spurious interrupt from DMA channel %d (CSR %04x)\n",
1112 ch, csr);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001113 return 0;
1114 }
Tony Lindgren7ff879d2006-06-26 16:16:15 -07001115 if (unlikely(csr & OMAP1_DMA_TOUT_IRQ))
Paul Walmsley7852ec02012-07-26 00:54:26 -06001116 pr_warn("DMA timeout with device %d\n", dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001117 if (unlikely(csr & OMAP_DMA_DROP_IRQ))
Paul Walmsley7852ec02012-07-26 00:54:26 -06001118 pr_warn("DMA synchronization event drop occurred with device %d\n",
1119 dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001120 if (likely(csr & OMAP_DMA_BLOCK_IRQ))
1121 dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
1122 if (likely(dma_chan[ch].callback != NULL))
1123 dma_chan[ch].callback(ch, csr, dma_chan[ch].data);
Tony Lindgren97b7f712008-07-03 12:24:37 +03001124
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001125 return 1;
1126}
1127
Linus Torvalds0cd61b62006-10-06 10:53:39 -07001128static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001129{
1130 int ch = ((int) dev_id) - 1;
1131 int handled = 0;
1132
1133 for (;;) {
1134 int handled_now = 0;
1135
1136 handled_now += omap1_dma_handle_ch(ch);
1137 if (enable_1510_mode && dma_chan[ch + 6].saved_csr)
1138 handled_now += omap1_dma_handle_ch(ch + 6);
1139 if (!handled_now)
1140 break;
1141 handled += handled_now;
1142 }
1143
1144 return handled ? IRQ_HANDLED : IRQ_NONE;
1145}
1146
1147#else
1148#define omap1_dma_irq_handler NULL
1149#endif
1150
Tony Lindgren140455f2010-02-12 12:26:48 -08001151#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001152
1153static int omap2_dma_handle_ch(int ch)
1154{
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001155 u32 status = p->dma_read(CSR, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001156
Juha Yrjola31513692006-12-06 17:13:47 -08001157 if (!status) {
1158 if (printk_ratelimit())
Paul Walmsley7852ec02012-07-26 00:54:26 -06001159 pr_warn("Spurious DMA IRQ for lch %d\n", ch);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001160 p->dma_write(1 << ch, IRQSTATUS_L0, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001161 return 0;
Juha Yrjola31513692006-12-06 17:13:47 -08001162 }
1163 if (unlikely(dma_chan[ch].dev_id == -1)) {
1164 if (printk_ratelimit())
Paul Walmsley7852ec02012-07-26 00:54:26 -06001165 pr_warn("IRQ %04x for non-allocated DMA channel %d\n",
1166 status, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001167 return 0;
Juha Yrjola31513692006-12-06 17:13:47 -08001168 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001169 if (unlikely(status & OMAP_DMA_DROP_IRQ))
Paul Walmsley7852ec02012-07-26 00:54:26 -06001170 pr_info("DMA synchronization event drop occurred with device %d\n",
1171 dma_chan[ch].dev_id);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001172 if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ)) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001173 printk(KERN_INFO "DMA transaction error with device %d\n",
1174 dma_chan[ch].dev_id);
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001175 if (IS_DMA_ERRATA(DMA_ERRATA_i378)) {
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001176 u32 ccr;
1177
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001178 ccr = p->dma_read(CCR, ch);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001179 ccr &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001180 p->dma_write(ccr, CCR, ch);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001181 dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
1182 }
1183 }
Tony Lindgren7ff879d2006-06-26 16:16:15 -07001184 if (unlikely(status & OMAP2_DMA_SECURE_ERR_IRQ))
1185 printk(KERN_INFO "DMA secure error with device %d\n",
1186 dma_chan[ch].dev_id);
1187 if (unlikely(status & OMAP2_DMA_MISALIGNED_ERR_IRQ))
1188 printk(KERN_INFO "DMA misaligned error with device %d\n",
1189 dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001190
Adrian Hunter4fb699b2010-11-24 13:23:21 +02001191 p->dma_write(status, CSR, ch);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001192 p->dma_write(1 << ch, IRQSTATUS_L0, ch);
Mathias Nymane860e6d2010-10-25 14:35:24 +00001193 /* read back the register to flush the write */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001194 p->dma_read(IRQSTATUS_L0, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001195
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001196 /* If the ch is not chained then chain_id will be -1 */
1197 if (dma_chan[ch].chain_id != -1) {
1198 int chain_id = dma_chan[ch].chain_id;
1199 dma_chan[ch].state = DMA_CH_NOTSTARTED;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001200 if (p->dma_read(CLNK_CTRL, ch) & (1 << 15))
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001201 dma_chan[dma_chan[ch].next_linked_ch].state =
1202 DMA_CH_STARTED;
1203 if (dma_linked_lch[chain_id].chain_mode ==
1204 OMAP_DMA_DYNAMIC_CHAIN)
1205 disable_lnk(ch);
1206
1207 if (!OMAP_DMA_CHAIN_QEMPTY(chain_id))
1208 OMAP_DMA_CHAIN_INCQHEAD(chain_id);
1209
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001210 status = p->dma_read(CSR, ch);
Adrian Hunter4fb699b2010-11-24 13:23:21 +02001211 p->dma_write(status, CSR, ch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001212 }
1213
Jarkko Nikula538528d2008-02-13 11:47:29 +02001214 if (likely(dma_chan[ch].callback != NULL))
1215 dma_chan[ch].callback(ch, status, dma_chan[ch].data);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001216
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001217 return 0;
1218}
1219
1220/* STATUS register count is from 1-32 while our is 0-31 */
Linus Torvalds0cd61b62006-10-06 10:53:39 -07001221static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001222{
Santosh Shilimkar52176e72009-03-23 18:07:49 -07001223 u32 val, enable_reg;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001224 int i;
1225
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001226 val = p->dma_read(IRQSTATUS_L0, 0);
Juha Yrjola31513692006-12-06 17:13:47 -08001227 if (val == 0) {
1228 if (printk_ratelimit())
1229 printk(KERN_WARNING "Spurious DMA IRQ\n");
1230 return IRQ_HANDLED;
1231 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001232 enable_reg = p->dma_read(IRQENABLE_L0, 0);
Santosh Shilimkar52176e72009-03-23 18:07:49 -07001233 val &= enable_reg; /* Dispatch only relevant interrupts */
Tony Lindgren4d963722008-07-03 12:24:31 +03001234 for (i = 0; i < dma_lch_count && val != 0; i++) {
Juha Yrjola31513692006-12-06 17:13:47 -08001235 if (val & 1)
1236 omap2_dma_handle_ch(i);
1237 val >>= 1;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001238 }
1239
1240 return IRQ_HANDLED;
1241}
1242
1243static struct irqaction omap24xx_dma_irq = {
1244 .name = "DMA",
1245 .handler = omap2_dma_irq_handler,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001246};
1247
1248#else
1249static struct irqaction omap24xx_dma_irq;
1250#endif
1251
1252/*----------------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001253
Tony Lindgren9ce24822014-05-16 14:05:35 -07001254/*
1255 * Note that we are currently using only IRQENABLE_L0 and L1.
1256 * As the DSP may be using IRQENABLE_L2 and L3, let's not
1257 * touch those for now.
1258 */
Tero Kristof2d11852008-08-28 13:13:31 +00001259void omap_dma_global_context_save(void)
1260{
1261 omap_dma_global_context.dma_irqenable_l0 =
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001262 p->dma_read(IRQENABLE_L0, 0);
Tony Lindgren9ce24822014-05-16 14:05:35 -07001263 omap_dma_global_context.dma_irqenable_l1 =
1264 p->dma_read(IRQENABLE_L1, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00001265 omap_dma_global_context.dma_ocp_sysconfig =
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001266 p->dma_read(OCP_SYSCONFIG, 0);
1267 omap_dma_global_context.dma_gcr = p->dma_read(GCR, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00001268}
1269
1270void omap_dma_global_context_restore(void)
1271{
Aaro Koskinenbf07c9f2009-05-20 16:58:30 +03001272 int ch;
1273
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001274 p->dma_write(omap_dma_global_context.dma_gcr, GCR, 0);
1275 p->dma_write(omap_dma_global_context.dma_ocp_sysconfig,
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001276 OCP_SYSCONFIG, 0);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001277 p->dma_write(omap_dma_global_context.dma_irqenable_l0,
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001278 IRQENABLE_L0, 0);
Tony Lindgren9ce24822014-05-16 14:05:35 -07001279 p->dma_write(omap_dma_global_context.dma_irqenable_l1,
1280 IRQENABLE_L1, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00001281
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001282 if (IS_DMA_ERRATA(DMA_ROMCODE_BUG))
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001283 p->dma_write(0x3 , IRQSTATUS_L0, 0);
Aaro Koskinenbf07c9f2009-05-20 16:58:30 +03001284
1285 for (ch = 0; ch < dma_chan_count; ch++)
1286 if (dma_chan[ch].dev_id != -1)
1287 omap_clear_dma(ch);
Tero Kristof2d11852008-08-28 13:13:31 +00001288}
1289
Russell King1b416c42013-11-02 13:00:03 +00001290struct omap_system_dma_plat_info *omap_get_plat_info(void)
1291{
1292 return p;
1293}
1294EXPORT_SYMBOL_GPL(omap_get_plat_info);
1295
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001296static int omap_system_dma_probe(struct platform_device *pdev)
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001297{
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001298 int ch, ret = 0;
1299 int dma_irq;
1300 char irq_name[4];
1301 int irq_rel;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001302
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001303 p = pdev->dev.platform_data;
1304 if (!p) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001305 dev_err(&pdev->dev,
1306 "%s: System DMA initialized without platform data\n",
1307 __func__);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001308 return -EINVAL;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001309 }
1310
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001311 d = p->dma_attr;
1312 errata = p->errata;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001313
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001314 if ((d->dev_caps & RESERVE_CHANNEL) && omap_dma_reserve_channels
Chen Gange78f9602013-01-11 13:39:18 +08001315 && (omap_dma_reserve_channels < d->lch_count))
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001316 d->lch_count = omap_dma_reserve_channels;
Santosh Shilimkar2263f022009-03-23 18:07:48 -07001317
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001318 dma_lch_count = d->lch_count;
1319 dma_chan_count = dma_lch_count;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001320 enable_1510_mode = d->dev_caps & ENABLE_1510_MODE;
Tony Lindgren4d963722008-07-03 12:24:31 +03001321
Russell King9834f812013-11-08 18:10:42 +00001322 dma_chan = devm_kcalloc(&pdev->dev, dma_lch_count,
1323 sizeof(struct omap_dma_lch), GFP_KERNEL);
1324 if (!dma_chan) {
1325 dev_err(&pdev->dev, "%s: kzalloc fail\n", __func__);
1326 return -ENOMEM;
1327 }
1328
1329
Tony Lindgren82809602012-10-30 11:03:22 -07001330 if (dma_omap2plus()) {
Tony Lindgren4d963722008-07-03 12:24:31 +03001331 dma_linked_lch = kzalloc(sizeof(struct dma_link_info) *
1332 dma_lch_count, GFP_KERNEL);
1333 if (!dma_linked_lch) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001334 ret = -ENOMEM;
1335 goto exit_dma_lch_fail;
Tony Lindgren4d963722008-07-03 12:24:31 +03001336 }
1337 }
1338
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001339 spin_lock_init(&dma_chan_lock);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001340 for (ch = 0; ch < dma_chan_count; ch++) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001341 omap_clear_dma(ch);
Tony Lindgren82809602012-10-30 11:03:22 -07001342 if (dma_omap2plus())
Mika Westerbergada8d4a2010-05-14 12:05:25 -07001343 omap2_disable_irq_lch(ch);
1344
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001345 dma_chan[ch].dev_id = -1;
1346 dma_chan[ch].next_lch = -1;
1347
1348 if (ch >= 6 && enable_1510_mode)
1349 continue;
1350
Tony Lindgren82809602012-10-30 11:03:22 -07001351 if (dma_omap1()) {
Tony Lindgren97b7f712008-07-03 12:24:37 +03001352 /*
1353 * request_irq() doesn't like dev_id (ie. ch) being
1354 * zero, so we have to kludge around this.
1355 */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001356 sprintf(&irq_name[0], "%d", ch);
1357 dma_irq = platform_get_irq_byname(pdev, irq_name);
1358
1359 if (dma_irq < 0) {
1360 ret = dma_irq;
1361 goto exit_dma_irq_fail;
1362 }
1363
1364 /* INT_DMA_LCD is handled in lcd_dma.c */
1365 if (dma_irq == INT_DMA_LCD)
1366 continue;
1367
1368 ret = request_irq(dma_irq,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001369 omap1_dma_irq_handler, 0, "DMA",
1370 (void *) (ch + 1));
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001371 if (ret != 0)
1372 goto exit_dma_irq_fail;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001373 }
1374 }
1375
Tony Lindgren82809602012-10-30 11:03:22 -07001376 if (d->dev_caps & IS_RW_PRIORITY)
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001377 omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE,
1378 DMA_DEFAULT_FIFO_DEPTH, 0);
1379
Nishanth Menon76be4a52014-06-12 17:15:22 +05301380 if (dma_omap2plus() && !(d->dev_caps & DMA_ENGINE_HANDLE_IRQ)) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001381 strcpy(irq_name, "0");
1382 dma_irq = platform_get_irq_byname(pdev, irq_name);
1383 if (dma_irq < 0) {
1384 dev_err(&pdev->dev, "failed: request IRQ %d", dma_irq);
Wei Yongjun94b1d612013-07-16 20:10:46 +08001385 ret = dma_irq;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001386 goto exit_dma_lch_fail;
1387 }
1388 ret = setup_irq(dma_irq, &omap24xx_dma_irq);
1389 if (ret) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001390 dev_err(&pdev->dev, "set_up failed for IRQ %d for DMA (error %d)\n",
1391 dma_irq, ret);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001392 goto exit_dma_lch_fail;
Kalle Jokiniemiba50ea72009-03-26 15:59:00 +02001393 }
Kalle Jokiniemiaecedb92009-06-23 13:30:24 +03001394 }
1395
Tony Lindgren82809602012-10-30 11:03:22 -07001396 /* reserve dma channels 0 and 1 in high security devices on 34xx */
1397 if (d->dev_caps & HS_CHANNELS_RESERVED) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001398 pr_info("Reserving DMA channels 0 and 1 for HS ROM code\n");
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001399 dma_chan[0].dev_id = 0;
1400 dma_chan[1].dev_id = 1;
1401 }
1402 p->show_dma_caps();
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001403 return 0;
Tony Lindgren7e9bf842009-10-19 15:25:15 -07001404
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001405exit_dma_irq_fail:
Paul Walmsley7852ec02012-07-26 00:54:26 -06001406 dev_err(&pdev->dev, "unable to request IRQ %d for DMA (error %d)\n",
1407 dma_irq, ret);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001408 for (irq_rel = 0; irq_rel < ch; irq_rel++) {
1409 dma_irq = platform_get_irq(pdev, irq_rel);
1410 free_irq(dma_irq, (void *)(irq_rel + 1));
1411 }
1412
1413exit_dma_lch_fail:
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001414 return ret;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001415}
1416
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001417static int omap_system_dma_remove(struct platform_device *pdev)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001418{
1419 int dma_irq;
1420
Tony Lindgren82809602012-10-30 11:03:22 -07001421 if (dma_omap2plus()) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001422 char irq_name[4];
1423 strcpy(irq_name, "0");
1424 dma_irq = platform_get_irq_byname(pdev, irq_name);
Nishanth Menon76be4a52014-06-12 17:15:22 +05301425 if (dma_irq >= 0)
1426 remove_irq(dma_irq, &omap24xx_dma_irq);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001427 } else {
1428 int irq_rel = 0;
1429 for ( ; irq_rel < dma_chan_count; irq_rel++) {
1430 dma_irq = platform_get_irq(pdev, irq_rel);
1431 free_irq(dma_irq, (void *)(irq_rel + 1));
1432 }
1433 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001434 return 0;
1435}
1436
1437static struct platform_driver omap_system_dma_driver = {
1438 .probe = omap_system_dma_probe,
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001439 .remove = omap_system_dma_remove,
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001440 .driver = {
1441 .name = "omap_dma_system"
1442 },
1443};
1444
1445static int __init omap_system_dma_init(void)
1446{
1447 return platform_driver_register(&omap_system_dma_driver);
1448}
1449arch_initcall(omap_system_dma_init);
1450
1451static void __exit omap_system_dma_exit(void)
1452{
1453 platform_driver_unregister(&omap_system_dma_driver);
1454}
1455
1456MODULE_DESCRIPTION("OMAP SYSTEM DMA DRIVER");
1457MODULE_LICENSE("GPL");
1458MODULE_ALIAS("platform:" DRIVER_NAME);
1459MODULE_AUTHOR("Texas Instruments Inc");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001460
Santosh Shilimkar2263f022009-03-23 18:07:48 -07001461/*
1462 * Reserve the omap SDMA channels using cmdline bootarg
1463 * "omap_dma_reserve_ch=". The valid range is 1 to 32
1464 */
1465static int __init omap_dma_cmdline_reserve_ch(char *str)
1466{
1467 if (get_option(&str, &omap_dma_reserve_channels) != 1)
1468 omap_dma_reserve_channels = 0;
1469 return 1;
1470}
1471
1472__setup("omap_dma_reserve_ch=", omap_dma_cmdline_reserve_ch);
1473
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001474