blob: 79f43acf9acb541487cad85bf7b49fb7f695d0d6 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002/*
3 * linux/arch/arm/plat-omap/dma.c
4 *
Tony Lindgren97b7f712008-07-03 12:24:37 +03005 * Copyright (C) 2003 - 2008 Nokia Corporation
Jan Engelhardt96de0e22007-10-19 23:21:04 +02006 * Author: Juha Yrjölä <juha.yrjola@nokia.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01007 * DMA channel linking for 1610 by Samuel Ortiz <samuel.ortiz@nokia.com>
8 * Graphics DMA and LCD DMA graphics tranformations
9 * by Imre Deak <imre.deak@nokia.com>
Anand Gadiyarf8151e52007-12-01 12:14:11 -080010 * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000011 * Merged to support both OMAP1 and OMAP2 by Tony Lindgren <tony@atomide.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010012 * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
13 *
Santosh Shilimkar44169072009-05-28 14:16:04 -070014 * Copyright (C) 2009 Texas Instruments
15 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
16 *
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010017 * Support functions for the OMAP internal DMA channels.
18 *
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -080019 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
20 * Converted DMA library into DMA platform driver.
21 * - G, Manjunath Kondaiah <manjugk@ti.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010022 */
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 Gleixner418ca1f02006-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
Tony Lindgren45c3eb72012-11-30 08:41:50 -080035#include <linux/omap-dma.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010036
Tony Lindgren685e2d02015-05-20 09:01:21 -070037#ifdef CONFIG_ARCH_OMAP1
38#include <mach/soc.h>
39#endif
40
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 void set_gdma_dev(int req, int dev)
155{
156 u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
157 int shift = ((req - 1) % 5) * 6;
158 u32 l;
159
160 l = omap_readl(reg);
161 l &= ~(0x3f << shift);
162 l |= (dev - 1) << shift;
163 omap_writel(l, reg);
164}
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000165#else
166#define set_gdma_dev(req, dev) do {} while (0)
Tony Lindgren2c799ce2012-02-24 10:34:35 -0800167#define omap_readl(reg) 0
168#define omap_writel(val, reg) do {} while (0)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000169#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100170
Tony Lindgren54b693d2012-10-02 13:39:28 -0700171#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300172void omap_set_dma_priority(int lch, int dst_port, int priority)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100173{
174 unsigned long reg;
175 u32 l;
176
Tony Lindgren82809602012-10-30 11:03:22 -0700177 if (dma_omap1()) {
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300178 switch (dst_port) {
179 case OMAP_DMA_PORT_OCP_T1: /* FFFECC00 */
180 reg = OMAP_TC_OCPT1_PRIOR;
181 break;
182 case OMAP_DMA_PORT_OCP_T2: /* FFFECCD0 */
183 reg = OMAP_TC_OCPT2_PRIOR;
184 break;
185 case OMAP_DMA_PORT_EMIFF: /* FFFECC08 */
186 reg = OMAP_TC_EMIFF_PRIOR;
187 break;
188 case OMAP_DMA_PORT_EMIFS: /* FFFECC04 */
189 reg = OMAP_TC_EMIFS_PRIOR;
190 break;
191 default:
192 BUG();
193 return;
194 }
195 l = omap_readl(reg);
196 l &= ~(0xf << 8);
197 l |= (priority & 0xf) << 8;
198 omap_writel(l, reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100199 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100200}
Tony Lindgren54b693d2012-10-02 13:39:28 -0700201#endif
202
203#ifdef CONFIG_ARCH_OMAP2PLUS
204void omap_set_dma_priority(int lch, int dst_port, int priority)
205{
206 u32 ccr;
207
208 ccr = p->dma_read(CCR, lch);
209 if (priority)
210 ccr |= (1 << 6);
211 else
212 ccr &= ~(1 << 6);
213 p->dma_write(ccr, CCR, lch);
214}
215#endif
Tony Lindgren97b7f712008-07-03 12:24:37 +0300216EXPORT_SYMBOL(omap_set_dma_priority);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100217
218void omap_set_dma_transfer_params(int lch, int data_type, int elem_count,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000219 int frame_count, int sync_mode,
220 int dma_trigger, int src_or_dst_synch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100221{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300222 u32 l;
223
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800224 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300225 l &= ~0x03;
226 l |= data_type;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800227 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100228
Tony Lindgren82809602012-10-30 11:03:22 -0700229 if (dma_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300230 u16 ccr;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100231
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800232 ccr = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300233 ccr &= ~(1 << 5);
234 if (sync_mode == OMAP_DMA_SYNC_FRAME)
235 ccr |= 1 << 5;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800236 p->dma_write(ccr, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300237
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800238 ccr = p->dma_read(CCR2, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300239 ccr &= ~(1 << 2);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000240 if (sync_mode == OMAP_DMA_SYNC_BLOCK)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300241 ccr |= 1 << 2;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800242 p->dma_write(ccr, CCR2, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000243 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100244
Tony Lindgren82809602012-10-30 11:03:22 -0700245 if (dma_omap2plus() && dma_trigger) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300246 u32 val;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100247
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800248 val = p->dma_read(CCR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100249
Anand Gadiyar4b3cf442009-01-15 13:09:53 +0200250 /* DMA_SYNCHRO_CONTROL_UPPER depends on the channel number */
Samu Onkalo72a11792010-08-02 14:21:40 +0300251 val &= ~((1 << 23) | (3 << 19) | 0x1f);
Anand Gadiyar4b3cf442009-01-15 13:09:53 +0200252 val |= (dma_trigger & ~0x1f) << 14;
253 val |= dma_trigger & 0x1f;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000254
255 if (sync_mode & OMAP_DMA_SYNC_FRAME)
256 val |= 1 << 5;
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700257 else
258 val &= ~(1 << 5);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000259
260 if (sync_mode & OMAP_DMA_SYNC_BLOCK)
261 val |= 1 << 18;
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700262 else
263 val &= ~(1 << 18);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000264
Samu Onkalo72a11792010-08-02 14:21:40 +0300265 if (src_or_dst_synch == OMAP_DMA_DST_SYNC_PREFETCH) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000266 val &= ~(1 << 24); /* dest synch */
Samu Onkalo72a11792010-08-02 14:21:40 +0300267 val |= (1 << 23); /* Prefetch */
268 } else if (src_or_dst_synch) {
269 val |= 1 << 24; /* source synch */
270 } else {
271 val &= ~(1 << 24); /* dest synch */
272 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800273 p->dma_write(val, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000274 }
275
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800276 p->dma_write(elem_count, CEN, lch);
277 p->dma_write(frame_count, CFN, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100278}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300279EXPORT_SYMBOL(omap_set_dma_transfer_params);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000280
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300281void omap_set_dma_write_mode(int lch, enum omap_dma_write_mode mode)
282{
Tony Lindgren82809602012-10-30 11:03:22 -0700283 if (dma_omap2plus()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300284 u32 csdp;
285
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800286 csdp = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300287 csdp &= ~(0x3 << 16);
288 csdp |= (mode << 16);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800289 p->dma_write(csdp, CSDP, lch);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300290 }
291}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300292EXPORT_SYMBOL(omap_set_dma_write_mode);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300293
Tony Lindgren0499bde2008-07-03 12:24:36 +0300294void omap_set_dma_channel_mode(int lch, enum omap_dma_channel_mode mode)
295{
Tony Lindgren82809602012-10-30 11:03:22 -0700296 if (dma_omap1() && !dma_omap15xx()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300297 u32 l;
298
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800299 l = p->dma_read(LCH_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300300 l &= ~0x7;
301 l |= mode;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800302 p->dma_write(l, LCH_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300303 }
304}
305EXPORT_SYMBOL(omap_set_dma_channel_mode);
306
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000307/* Note that src_port is only for omap1 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100308void omap_set_dma_src_params(int lch, int src_port, int src_amode,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000309 unsigned long src_start,
310 int src_ei, int src_fi)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100311{
Tony Lindgren97b7f712008-07-03 12:24:37 +0300312 u32 l;
313
Tony Lindgren82809602012-10-30 11:03:22 -0700314 if (dma_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300315 u16 w;
316
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800317 w = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300318 w &= ~(0x1f << 2);
319 w |= src_port << 2;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800320 p->dma_write(w, CSDP, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300321 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300322
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800323 l = p->dma_read(CCR, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300324 l &= ~(0x03 << 12);
325 l |= src_amode << 12;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800326 p->dma_write(l, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300327
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800328 p->dma_write(src_start, CSSA, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100329
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800330 p->dma_write(src_ei, CSEI, lch);
331 p->dma_write(src_fi, CSFI, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300332}
333EXPORT_SYMBOL(omap_set_dma_src_params);
334
335void omap_set_dma_params(int lch, struct omap_dma_channel_params *params)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000336{
337 omap_set_dma_transfer_params(lch, params->data_type,
338 params->elem_count, params->frame_count,
339 params->sync_mode, params->trigger,
340 params->src_or_dst_synch);
341 omap_set_dma_src_params(lch, params->src_port,
342 params->src_amode, params->src_start,
343 params->src_ei, params->src_fi);
344
345 omap_set_dma_dest_params(lch, params->dst_port,
346 params->dst_amode, params->dst_start,
347 params->dst_ei, params->dst_fi);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800348 if (params->read_prio || params->write_prio)
349 omap_dma_set_prio_lch(lch, params->read_prio,
350 params->write_prio);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100351}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300352EXPORT_SYMBOL(omap_set_dma_params);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100353
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100354void omap_set_dma_src_data_pack(int lch, int enable)
355{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300356 u32 l;
357
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800358 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300359 l &= ~(1 << 6);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000360 if (enable)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300361 l |= (1 << 6);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800362 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100363}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300364EXPORT_SYMBOL(omap_set_dma_src_data_pack);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100365
366void omap_set_dma_src_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
367{
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700368 unsigned int burst = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300369 u32 l;
370
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800371 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300372 l &= ~(0x03 << 7);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100373
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100374 switch (burst_mode) {
375 case OMAP_DMA_DATA_BURST_DIS:
376 break;
377 case OMAP_DMA_DATA_BURST_4:
Tony Lindgren82809602012-10-30 11:03:22 -0700378 if (dma_omap2plus())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700379 burst = 0x1;
380 else
381 burst = 0x2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100382 break;
383 case OMAP_DMA_DATA_BURST_8:
Tony Lindgren82809602012-10-30 11:03:22 -0700384 if (dma_omap2plus()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700385 burst = 0x2;
386 break;
387 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700388 /*
389 * not supported by current hardware on OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100390 * w |= (0x03 << 7);
391 * fall through
392 */
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700393 case OMAP_DMA_DATA_BURST_16:
Tony Lindgren82809602012-10-30 11:03:22 -0700394 if (dma_omap2plus()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700395 burst = 0x3;
396 break;
397 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700398 /*
399 * OMAP1 don't support burst 16
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700400 * fall through
401 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100402 default:
403 BUG();
404 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300405
406 l |= (burst << 7);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800407 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100408}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300409EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100410
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000411/* Note that dest_port is only for OMAP1 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100412void omap_set_dma_dest_params(int lch, int dest_port, int dest_amode,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000413 unsigned long dest_start,
414 int dst_ei, int dst_fi)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100415{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300416 u32 l;
417
Tony Lindgren82809602012-10-30 11:03:22 -0700418 if (dma_omap1()) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800419 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300420 l &= ~(0x1f << 9);
421 l |= dest_port << 9;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800422 p->dma_write(l, CSDP, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000423 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100424
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800425 l = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300426 l &= ~(0x03 << 14);
427 l |= dest_amode << 14;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800428 p->dma_write(l, CCR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100429
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800430 p->dma_write(dest_start, CDSA, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100431
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800432 p->dma_write(dst_ei, CDEI, lch);
433 p->dma_write(dst_fi, CDFI, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100434}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300435EXPORT_SYMBOL(omap_set_dma_dest_params);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100436
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100437void omap_set_dma_dest_data_pack(int lch, int enable)
438{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300439 u32 l;
440
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800441 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300442 l &= ~(1 << 13);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000443 if (enable)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300444 l |= 1 << 13;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800445 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100446}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300447EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100448
449void omap_set_dma_dest_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
450{
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700451 unsigned int burst = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300452 u32 l;
453
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800454 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300455 l &= ~(0x03 << 14);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100456
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100457 switch (burst_mode) {
458 case OMAP_DMA_DATA_BURST_DIS:
459 break;
460 case OMAP_DMA_DATA_BURST_4:
Tony Lindgren82809602012-10-30 11:03:22 -0700461 if (dma_omap2plus())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700462 burst = 0x1;
463 else
464 burst = 0x2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100465 break;
466 case OMAP_DMA_DATA_BURST_8:
Tony Lindgren82809602012-10-30 11:03:22 -0700467 if (dma_omap2plus())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700468 burst = 0x2;
469 else
470 burst = 0x3;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100471 break;
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700472 case OMAP_DMA_DATA_BURST_16:
Tony Lindgren82809602012-10-30 11:03:22 -0700473 if (dma_omap2plus()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700474 burst = 0x3;
475 break;
476 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700477 /*
478 * OMAP1 don't support burst 16
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700479 * fall through
480 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100481 default:
482 printk(KERN_ERR "Invalid DMA burst mode\n");
483 BUG();
484 return;
485 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300486 l |= (burst << 14);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800487 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100488}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300489EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100490
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000491static inline void omap_enable_channel_irq(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100492{
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700493 /* Clear CSR */
Tony Lindgren82809602012-10-30 11:03:22 -0700494 if (dma_omap1())
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700495 p->dma_read(CSR, lch);
496 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800497 p->dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000498
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100499 /* Enable some nice interrupts. */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800500 p->dma_write(dma_chan[lch].enabled_irqs, CICR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100501}
502
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700503static inline void omap_disable_channel_irq(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100504{
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700505 /* disable channel interrupts */
506 p->dma_write(0, CICR, lch);
507 /* Clear CSR */
Tony Lindgren82809602012-10-30 11:03:22 -0700508 if (dma_omap1())
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700509 p->dma_read(CSR, lch);
510 else
511 p->dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100512}
513
514void omap_enable_dma_irq(int lch, u16 bits)
515{
516 dma_chan[lch].enabled_irqs |= bits;
517}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300518EXPORT_SYMBOL(omap_enable_dma_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100519
520void omap_disable_dma_irq(int lch, u16 bits)
521{
522 dma_chan[lch].enabled_irqs &= ~bits;
523}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300524EXPORT_SYMBOL(omap_disable_dma_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100525
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000526static inline void enable_lnk(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100527{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300528 u32 l;
529
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800530 l = p->dma_read(CLNK_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300531
Tony Lindgren82809602012-10-30 11:03:22 -0700532 if (dma_omap1())
Tony Lindgren0499bde2008-07-03 12:24:36 +0300533 l &= ~(1 << 14);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100534
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000535 /* Set the ENABLE_LNK bits */
536 if (dma_chan[lch].next_lch != -1)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300537 l = dma_chan[lch].next_lch | (1 << 15);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800538
539#ifndef CONFIG_ARCH_OMAP1
Tony Lindgren82809602012-10-30 11:03:22 -0700540 if (dma_omap2plus())
Tony Lindgren97b7f712008-07-03 12:24:37 +0300541 if (dma_chan[lch].next_linked_ch != -1)
542 l = dma_chan[lch].next_linked_ch | (1 << 15);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800543#endif
Tony Lindgren0499bde2008-07-03 12:24:36 +0300544
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800545 p->dma_write(l, CLNK_CTRL, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100546}
547
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000548static inline void disable_lnk(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100549{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300550 u32 l;
551
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800552 l = p->dma_read(CLNK_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300553
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000554 /* Disable interrupts */
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700555 omap_disable_channel_irq(lch);
556
Tony Lindgren82809602012-10-30 11:03:22 -0700557 if (dma_omap1()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000558 /* Set the STOP_LNK bit */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300559 l |= 1 << 14;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100560 }
561
Tony Lindgren82809602012-10-30 11:03:22 -0700562 if (dma_omap2plus()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000563 /* Clear the ENABLE_LNK bit */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300564 l &= ~(1 << 15);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000565 }
566
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800567 p->dma_write(l, CLNK_CTRL, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000568 dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
569}
570
571static inline void omap2_enable_irq_lch(int lch)
572{
573 u32 val;
Tao Huee907322009-11-10 18:55:17 -0800574 unsigned long flags;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000575
Tony Lindgren82809602012-10-30 11:03:22 -0700576 if (dma_omap1())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000577 return;
578
Tao Huee907322009-11-10 18:55:17 -0800579 spin_lock_irqsave(&dma_chan_lock, flags);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700580 /* clear IRQ STATUS */
581 p->dma_write(1 << lch, IRQSTATUS_L0, lch);
582 /* Enable interrupt */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800583 val = p->dma_read(IRQENABLE_L0, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000584 val |= 1 << lch;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800585 p->dma_write(val, IRQENABLE_L0, lch);
Tao Huee907322009-11-10 18:55:17 -0800586 spin_unlock_irqrestore(&dma_chan_lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100587}
588
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700589static inline void omap2_disable_irq_lch(int lch)
590{
591 u32 val;
592 unsigned long flags;
593
Tony Lindgren82809602012-10-30 11:03:22 -0700594 if (dma_omap1())
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700595 return;
596
597 spin_lock_irqsave(&dma_chan_lock, flags);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700598 /* Disable interrupt */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800599 val = p->dma_read(IRQENABLE_L0, lch);
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700600 val &= ~(1 << lch);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800601 p->dma_write(val, IRQENABLE_L0, lch);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700602 /* clear IRQ STATUS */
603 p->dma_write(1 << lch, IRQSTATUS_L0, lch);
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700604 spin_unlock_irqrestore(&dma_chan_lock, flags);
605}
606
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100607int omap_request_dma(int dev_id, const char *dev_name,
Tony Lindgren97b7f712008-07-03 12:24:37 +0300608 void (*callback)(int lch, u16 ch_status, void *data),
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100609 void *data, int *dma_ch_out)
610{
611 int ch, free_ch = -1;
612 unsigned long flags;
613 struct omap_dma_lch *chan;
614
Russell King5c65c362014-06-07 10:47:36 +0100615 WARN(strcmp(dev_name, "DMA engine"), "Using deprecated platform DMA API - please update to DMA engine");
616
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100617 spin_lock_irqsave(&dma_chan_lock, flags);
618 for (ch = 0; ch < dma_chan_count; ch++) {
619 if (free_ch == -1 && dma_chan[ch].dev_id == -1) {
620 free_ch = ch;
R Sricharan03a6d4a2013-06-13 19:47:09 +0530621 /* Exit after first free channel found */
622 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100623 }
624 }
625 if (free_ch == -1) {
626 spin_unlock_irqrestore(&dma_chan_lock, flags);
627 return -EBUSY;
628 }
629 chan = dma_chan + free_ch;
630 chan->dev_id = dev_id;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000631
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800632 if (p->clear_lch_regs)
633 p->clear_lch_regs(free_ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000634
Tony Lindgren82809602012-10-30 11:03:22 -0700635 if (dma_omap2plus())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000636 omap_clear_dma(free_ch);
637
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100638 spin_unlock_irqrestore(&dma_chan_lock, flags);
639
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100640 chan->dev_name = dev_name;
641 chan->callback = callback;
642 chan->data = data;
Jarkko Nikulaa92fda12009-01-29 08:57:12 -0800643 chan->flags = 0;
Tony Lindgren97b7f712008-07-03 12:24:37 +0300644
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800645#ifndef CONFIG_ARCH_OMAP1
Tony Lindgren82809602012-10-30 11:03:22 -0700646 if (dma_omap2plus()) {
Tony Lindgren97b7f712008-07-03 12:24:37 +0300647 chan->chain_id = -1;
648 chan->next_linked_ch = -1;
649 }
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800650#endif
Tony Lindgren97b7f712008-07-03 12:24:37 +0300651
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700652 chan->enabled_irqs = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000653
Tony Lindgren82809602012-10-30 11:03:22 -0700654 if (dma_omap1())
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700655 chan->enabled_irqs |= OMAP1_DMA_TOUT_IRQ;
Tony Lindgren82809602012-10-30 11:03:22 -0700656 else if (dma_omap2plus())
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700657 chan->enabled_irqs |= OMAP2_DMA_MISALIGNED_ERR_IRQ |
658 OMAP2_DMA_TRANS_ERR_IRQ;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100659
Tony Lindgren82809602012-10-30 11:03:22 -0700660 if (dma_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100661 /* If the sync device is set, configure it dynamically. */
662 if (dev_id != 0) {
663 set_gdma_dev(free_ch + 1, dev_id);
664 dev_id = free_ch + 1;
665 }
Tony Lindgren97b7f712008-07-03 12:24:37 +0300666 /*
667 * Disable the 1510 compatibility mode and set the sync device
668 * id.
669 */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800670 p->dma_write(dev_id | (1 << 10), CCR, free_ch);
Tony Lindgren82809602012-10-30 11:03:22 -0700671 } else if (dma_omap1()) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800672 p->dma_write(dev_id, CCR, free_ch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100673 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000674
Tony Lindgren82809602012-10-30 11:03:22 -0700675 if (dma_omap2plus()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000676 omap_enable_channel_irq(free_ch);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700677 omap2_enable_irq_lch(free_ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000678 }
679
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100680 *dma_ch_out = free_ch;
681
682 return 0;
683}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300684EXPORT_SYMBOL(omap_request_dma);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100685
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000686void omap_free_dma(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100687{
688 unsigned long flags;
689
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000690 if (dma_chan[lch].dev_id == -1) {
Tony Lindgren97b7f712008-07-03 12:24:37 +0300691 pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000692 lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100693 return;
694 }
Tony Lindgren97b7f712008-07-03 12:24:37 +0300695
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700696 /* Disable interrupt for logical channel */
Tony Lindgren82809602012-10-30 11:03:22 -0700697 if (dma_omap2plus())
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700698 omap2_disable_irq_lch(lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000699
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700700 /* Disable all DMA interrupts for the channel. */
701 omap_disable_channel_irq(lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000702
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700703 /* Make sure the DMA transfer is stopped. */
704 p->dma_write(0, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000705
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700706 /* Clear registers */
Tony Lindgren82809602012-10-30 11:03:22 -0700707 if (dma_omap2plus())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000708 omap_clear_dma(lch);
Santosh Shilimkarda1b94e2009-04-23 11:10:40 -0700709
710 spin_lock_irqsave(&dma_chan_lock, flags);
711 dma_chan[lch].dev_id = -1;
712 dma_chan[lch].next_lch = -1;
713 dma_chan[lch].callback = NULL;
714 spin_unlock_irqrestore(&dma_chan_lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100715}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300716EXPORT_SYMBOL(omap_free_dma);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100717
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800718/**
719 * @brief omap_dma_set_global_params : Set global priority settings for dma
720 *
721 * @param arb_rate
722 * @param max_fifo_depth
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700723 * @param tparams - Number of threads to reserve : DMA_THREAD_RESERVE_NORM
724 * DMA_THREAD_RESERVE_ONET
725 * DMA_THREAD_RESERVE_TWOT
726 * DMA_THREAD_RESERVE_THREET
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800727 */
728void
729omap_dma_set_global_params(int arb_rate, int max_fifo_depth, int tparams)
730{
731 u32 reg;
732
Tony Lindgren82809602012-10-30 11:03:22 -0700733 if (dma_omap1()) {
Harvey Harrison8e86f422008-03-04 15:08:02 -0800734 printk(KERN_ERR "FIXME: no %s on 15xx/16xx\n", __func__);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800735 return;
736 }
737
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700738 if (max_fifo_depth == 0)
739 max_fifo_depth = 1;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800740 if (arb_rate == 0)
741 arb_rate = 1;
742
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700743 reg = 0xff & max_fifo_depth;
744 reg |= (0x3 & tparams) << 12;
745 reg |= (arb_rate & 0xff) << 16;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800746
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800747 p->dma_write(reg, GCR, 0);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800748}
749EXPORT_SYMBOL(omap_dma_set_global_params);
750
751/**
752 * @brief omap_dma_set_prio_lch : Set channel wise priority settings
753 *
754 * @param lch
755 * @param read_prio - Read priority
756 * @param write_prio - Write priority
757 * Both of the above can be set with one of the following values :
758 * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW
759 */
Tony Lindgren175655b2014-09-16 17:36:28 -0700760static int
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800761omap_dma_set_prio_lch(int lch, unsigned char read_prio,
762 unsigned char write_prio)
763{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300764 u32 l;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800765
Tony Lindgren4d963722008-07-03 12:24:31 +0300766 if (unlikely((lch < 0 || lch >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800767 printk(KERN_ERR "Invalid channel id\n");
768 return -EINVAL;
769 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800770 l = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300771 l &= ~((1 << 6) | (1 << 26));
Tony Lindgren82809602012-10-30 11:03:22 -0700772 if (d->dev_caps & IS_RW_PRIORITY)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300773 l |= ((read_prio & 0x1) << 6) | ((write_prio & 0x1) << 26);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800774 else
Tony Lindgren0499bde2008-07-03 12:24:36 +0300775 l |= ((read_prio & 0x1) << 6);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800776
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800777 p->dma_write(l, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300778
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800779 return 0;
780}
Tony Lindgren175655b2014-09-16 17:36:28 -0700781
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800782
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000783/*
784 * Clears any DMA state so the DMA engine is ready to restart with new buffers
785 * through omap_start_dma(). Any buffers in flight are discarded.
786 */
Tony Lindgren175655b2014-09-16 17:36:28 -0700787static void omap_clear_dma(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100788{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000789 unsigned long flags;
790
791 local_irq_save(flags);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800792 p->clear_dma(lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000793 local_irq_restore(flags);
794}
795
796void omap_start_dma(int lch)
797{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300798 u32 l;
799
manjugk manjugk519e6162010-03-04 07:11:56 +0000800 /*
801 * The CPC/CDAC register needs to be initialized to zero
802 * before starting dma transfer.
803 */
Tony Lindgren82809602012-10-30 11:03:22 -0700804 if (dma_omap15xx())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800805 p->dma_write(0, CPC, lch);
manjugk manjugk519e6162010-03-04 07:11:56 +0000806 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800807 p->dma_write(0, CDAC, lch);
manjugk manjugk519e6162010-03-04 07:11:56 +0000808
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000809 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
810 int next_lch, cur_lch;
Paul Walmsleybc4d8b52012-04-13 06:34:30 -0600811 char dma_chan_link_map[MAX_LOGICAL_DMA_CH_COUNT];
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000812
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000813 /* Set the link register of the first channel */
814 enable_lnk(lch);
815
816 memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
R Sricharanf0a3ff22013-06-13 19:47:10 +0530817 dma_chan_link_map[lch] = 1;
818
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000819 cur_lch = dma_chan[lch].next_lch;
820 do {
821 next_lch = dma_chan[cur_lch].next_lch;
822
823 /* The loop case: we've been here already */
824 if (dma_chan_link_map[cur_lch])
825 break;
826 /* Mark the current channel */
827 dma_chan_link_map[cur_lch] = 1;
828
829 enable_lnk(cur_lch);
830 omap_enable_channel_irq(cur_lch);
831
832 cur_lch = next_lch;
833 } while (next_lch != -1);
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800834 } else if (IS_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS))
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800835 p->dma_write(lch, CLNK_CTRL, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000836
837 omap_enable_channel_irq(lch);
838
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800839 l = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300840
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800841 if (IS_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING))
842 l |= OMAP_DMA_CCR_BUFFERING_DISABLE;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300843 l |= OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800844
Russell King35453582012-04-14 18:57:10 +0100845 /*
846 * As dma_write() uses IO accessors which are weakly ordered, there
847 * is no guarantee that data in coherent DMA memory will be visible
848 * to the DMA device. Add a memory barrier here to ensure that any
849 * such data is visible prior to enabling DMA.
850 */
851 mb();
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800852 p->dma_write(l, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000853
854 dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
855}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300856EXPORT_SYMBOL(omap_start_dma);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000857
858void omap_stop_dma(int lch)
859{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300860 u32 l;
861
Santosh Shilimkar9da65a92009-10-22 14:46:31 -0700862 /* Disable all interrupts on the channel */
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700863 omap_disable_channel_irq(lch);
Santosh Shilimkar9da65a92009-10-22 14:46:31 -0700864
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800865 l = p->dma_read(CCR, lch);
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800866 if (IS_DMA_ERRATA(DMA_ERRATA_i541) &&
867 (l & OMAP_DMA_CCR_SEL_SRC_DST_SYNC)) {
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700868 int i = 0;
869 u32 sys_cf;
870
871 /* Configure No-Standby */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800872 l = p->dma_read(OCP_SYSCONFIG, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700873 sys_cf = l;
874 l &= ~DMA_SYSCONFIG_MIDLEMODE_MASK;
875 l |= DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_NO_IDLE);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800876 p->dma_write(l , OCP_SYSCONFIG, 0);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700877
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800878 l = p->dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700879 l &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800880 p->dma_write(l, CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700881
882 /* Wait for sDMA FIFO drain */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800883 l = p->dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700884 while (i < 100 && (l & (OMAP_DMA_CCR_RD_ACTIVE |
885 OMAP_DMA_CCR_WR_ACTIVE))) {
886 udelay(5);
887 i++;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800888 l = p->dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700889 }
890 if (i >= 100)
Paul Walmsley7852ec02012-07-26 00:54:26 -0600891 pr_err("DMA drain did not complete on lch %d\n", lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700892 /* Restore OCP_SYSCONFIG */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800893 p->dma_write(sys_cf, OCP_SYSCONFIG, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700894 } else {
895 l &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800896 p->dma_write(l, CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700897 }
Santosh Shilimkar9da65a92009-10-22 14:46:31 -0700898
Russell King35453582012-04-14 18:57:10 +0100899 /*
900 * Ensure that data transferred by DMA is visible to any access
901 * after DMA has been disabled. This is important for coherent
902 * DMA regions.
903 */
904 mb();
905
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000906 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
907 int next_lch, cur_lch = lch;
Paul Walmsleybc4d8b52012-04-13 06:34:30 -0600908 char dma_chan_link_map[MAX_LOGICAL_DMA_CH_COUNT];
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000909
910 memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
911 do {
912 /* The loop case: we've been here already */
913 if (dma_chan_link_map[cur_lch])
914 break;
915 /* Mark the current channel */
916 dma_chan_link_map[cur_lch] = 1;
917
918 disable_lnk(cur_lch);
919
920 next_lch = dma_chan[cur_lch].next_lch;
921 cur_lch = next_lch;
922 } while (next_lch != -1);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000923 }
924
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000925 dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
926}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300927EXPORT_SYMBOL(omap_stop_dma);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000928
929/*
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300930 * Allows changing the DMA callback function or data. This may be needed if
931 * the driver shares a single DMA channel for multiple dma triggers.
932 */
933int omap_set_dma_callback(int lch,
Tony Lindgren97b7f712008-07-03 12:24:37 +0300934 void (*callback)(int lch, u16 ch_status, void *data),
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300935 void *data)
936{
937 unsigned long flags;
938
939 if (lch < 0)
940 return -ENODEV;
941
942 spin_lock_irqsave(&dma_chan_lock, flags);
943 if (dma_chan[lch].dev_id == -1) {
944 printk(KERN_ERR "DMA callback for not set for free channel\n");
945 spin_unlock_irqrestore(&dma_chan_lock, flags);
946 return -EINVAL;
947 }
948 dma_chan[lch].callback = callback;
949 dma_chan[lch].data = data;
950 spin_unlock_irqrestore(&dma_chan_lock, flags);
951
952 return 0;
953}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300954EXPORT_SYMBOL(omap_set_dma_callback);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300955
956/*
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000957 * Returns current physical source address for the given DMA channel.
958 * If the channel is running the caller must disable interrupts prior calling
959 * this function and process the returned value before re-enabling interrupt to
960 * prevent races with the interrupt handler. Note that in continuous mode there
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300961 * is a chance for CSSA_L register overflow between the two reads resulting
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000962 * in incorrect return value.
963 */
964dma_addr_t omap_get_dma_src_pos(int lch)
965{
Tony Lindgren0695de32007-05-07 18:24:14 -0700966 dma_addr_t offset = 0;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000967
Tony Lindgren82809602012-10-30 11:03:22 -0700968 if (dma_omap15xx())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800969 offset = p->dma_read(CPC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300970 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800971 offset = p->dma_read(CSAC, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000972
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800973 if (IS_DMA_ERRATA(DMA_ERRATA_3_3) && offset == 0)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800974 offset = p->dma_read(CSAC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300975
Tony Lindgren82809602012-10-30 11:03:22 -0700976 if (!dma_omap15xx()) {
Peter Ujfalusi7ba96682011-12-09 13:38:00 -0800977 /*
978 * CDAC == 0 indicates that the DMA transfer on the channel has
979 * not been started (no data has been transferred so far).
980 * Return the programmed source start address in this case.
981 */
982 if (likely(p->dma_read(CDAC, lch)))
983 offset = p->dma_read(CSAC, lch);
984 else
985 offset = p->dma_read(CSSA, lch);
986 }
987
Tony Lindgren82809602012-10-30 11:03:22 -0700988 if (dma_omap1())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800989 offset |= (p->dma_read(CSSA, lch) & 0xFFFF0000);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000990
991 return offset;
992}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300993EXPORT_SYMBOL(omap_get_dma_src_pos);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000994
995/*
996 * Returns current physical destination address for the given DMA channel.
997 * If the channel is running the caller must disable interrupts prior calling
998 * this function and process the returned value before re-enabling interrupt to
999 * prevent races with the interrupt handler. Note that in continuous mode there
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001000 * is a chance for CDSA_L register overflow between the two reads resulting
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001001 * in incorrect return value.
1002 */
1003dma_addr_t omap_get_dma_dst_pos(int lch)
1004{
Tony Lindgren0695de32007-05-07 18:24:14 -07001005 dma_addr_t offset = 0;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001006
Tony Lindgren82809602012-10-30 11:03:22 -07001007 if (dma_omap15xx())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001008 offset = p->dma_read(CPC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001009 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001010 offset = p->dma_read(CDAC, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001011
Tony Lindgren0499bde2008-07-03 12:24:36 +03001012 /*
1013 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1014 * read before the DMA controller finished disabling the channel.
1015 */
Tony Lindgren82809602012-10-30 11:03:22 -07001016 if (!dma_omap15xx() && offset == 0) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001017 offset = p->dma_read(CDAC, lch);
Peter Ujfalusi06e80772011-12-09 13:38:00 -08001018 /*
1019 * CDAC == 0 indicates that the DMA transfer on the channel has
1020 * not been started (no data has been transferred so far).
1021 * Return the programmed destination start address in this case.
1022 */
1023 if (unlikely(!offset))
1024 offset = p->dma_read(CDSA, lch);
1025 }
Tony Lindgren0499bde2008-07-03 12:24:36 +03001026
Tony Lindgren82809602012-10-30 11:03:22 -07001027 if (dma_omap1())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001028 offset |= (p->dma_read(CDSA, lch) & 0xFFFF0000);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001029
1030 return offset;
1031}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001032EXPORT_SYMBOL(omap_get_dma_dst_pos);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001033
Tony Lindgren0499bde2008-07-03 12:24:36 +03001034int omap_get_dma_active_status(int lch)
1035{
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001036 return (p->dma_read(CCR, lch) & OMAP_DMA_CCR_EN) != 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001037}
1038EXPORT_SYMBOL(omap_get_dma_active_status);
1039
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001040int omap_dma_running(void)
1041{
1042 int lch;
1043
Tony Lindgren82809602012-10-30 11:03:22 -07001044 if (dma_omap1())
Janusz Krzysztofikf8e9e982009-12-11 16:16:33 -08001045 if (omap_lcd_dma_running())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001046 return 1;
1047
1048 for (lch = 0; lch < dma_chan_count; lch++)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001049 if (p->dma_read(CCR, lch) & OMAP_DMA_CCR_EN)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001050 return 1;
1051
1052 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001053}
1054
1055/*
1056 * lch_queue DMA will start right after lch_head one is finished.
1057 * For this DMA link to start, you still need to start (see omap_start_dma)
1058 * the first one. That will fire up the entire queue.
1059 */
Tony Lindgren97b7f712008-07-03 12:24:37 +03001060void omap_dma_link_lch(int lch_head, int lch_queue)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001061{
1062 if (omap_dma_in_1510_mode()) {
Janusz Krzysztofik9f0f4ae2009-08-23 17:56:12 +02001063 if (lch_head == lch_queue) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001064 p->dma_write(p->dma_read(CCR, lch_head) | (3 << 8),
G, Manjunath Kondaiaha4c537c72010-12-20 18:27:17 -08001065 CCR, lch_head);
Janusz Krzysztofik9f0f4ae2009-08-23 17:56:12 +02001066 return;
1067 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001068 printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
1069 BUG();
1070 return;
1071 }
1072
1073 if ((dma_chan[lch_head].dev_id == -1) ||
1074 (dma_chan[lch_queue].dev_id == -1)) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001075 pr_err("omap_dma: trying to link non requested channels\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001076 dump_stack();
1077 }
1078
1079 dma_chan[lch_head].next_lch = lch_queue;
1080}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001081EXPORT_SYMBOL(omap_dma_link_lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001082
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001083/*----------------------------------------------------------------------------*/
1084
1085#ifdef CONFIG_ARCH_OMAP1
1086
1087static int omap1_dma_handle_ch(int ch)
1088{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001089 u32 csr;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001090
1091 if (enable_1510_mode && ch >= 6) {
1092 csr = dma_chan[ch].saved_csr;
1093 dma_chan[ch].saved_csr = 0;
1094 } else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001095 csr = p->dma_read(CSR, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001096 if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) {
1097 dma_chan[ch + 6].saved_csr = csr >> 7;
1098 csr &= 0x7f;
1099 }
1100 if ((csr & 0x3f) == 0)
1101 return 0;
1102 if (unlikely(dma_chan[ch].dev_id == -1)) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001103 pr_warn("Spurious interrupt from DMA channel %d (CSR %04x)\n",
1104 ch, csr);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001105 return 0;
1106 }
Tony Lindgren7ff879d2006-06-26 16:16:15 -07001107 if (unlikely(csr & OMAP1_DMA_TOUT_IRQ))
Paul Walmsley7852ec02012-07-26 00:54:26 -06001108 pr_warn("DMA timeout with device %d\n", dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001109 if (unlikely(csr & OMAP_DMA_DROP_IRQ))
Paul Walmsley7852ec02012-07-26 00:54:26 -06001110 pr_warn("DMA synchronization event drop occurred with device %d\n",
1111 dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001112 if (likely(csr & OMAP_DMA_BLOCK_IRQ))
1113 dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
1114 if (likely(dma_chan[ch].callback != NULL))
1115 dma_chan[ch].callback(ch, csr, dma_chan[ch].data);
Tony Lindgren97b7f712008-07-03 12:24:37 +03001116
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001117 return 1;
1118}
1119
Linus Torvalds0cd61b62006-10-06 10:53:39 -07001120static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001121{
1122 int ch = ((int) dev_id) - 1;
1123 int handled = 0;
1124
1125 for (;;) {
1126 int handled_now = 0;
1127
1128 handled_now += omap1_dma_handle_ch(ch);
1129 if (enable_1510_mode && dma_chan[ch + 6].saved_csr)
1130 handled_now += omap1_dma_handle_ch(ch + 6);
1131 if (!handled_now)
1132 break;
1133 handled += handled_now;
1134 }
1135
1136 return handled ? IRQ_HANDLED : IRQ_NONE;
1137}
1138
1139#else
1140#define omap1_dma_irq_handler NULL
1141#endif
1142
Tony Lindgren140455f2010-02-12 12:26:48 -08001143#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001144
1145static int omap2_dma_handle_ch(int ch)
1146{
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001147 u32 status = p->dma_read(CSR, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001148
Juha Yrjola31513692006-12-06 17:13:47 -08001149 if (!status) {
1150 if (printk_ratelimit())
Paul Walmsley7852ec02012-07-26 00:54:26 -06001151 pr_warn("Spurious DMA IRQ for lch %d\n", ch);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001152 p->dma_write(1 << ch, IRQSTATUS_L0, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001153 return 0;
Juha Yrjola31513692006-12-06 17:13:47 -08001154 }
1155 if (unlikely(dma_chan[ch].dev_id == -1)) {
1156 if (printk_ratelimit())
Paul Walmsley7852ec02012-07-26 00:54:26 -06001157 pr_warn("IRQ %04x for non-allocated DMA channel %d\n",
1158 status, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001159 return 0;
Juha Yrjola31513692006-12-06 17:13:47 -08001160 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001161 if (unlikely(status & OMAP_DMA_DROP_IRQ))
Paul Walmsley7852ec02012-07-26 00:54:26 -06001162 pr_info("DMA synchronization event drop occurred with device %d\n",
1163 dma_chan[ch].dev_id);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001164 if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ)) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001165 printk(KERN_INFO "DMA transaction error with device %d\n",
1166 dma_chan[ch].dev_id);
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001167 if (IS_DMA_ERRATA(DMA_ERRATA_i378)) {
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001168 u32 ccr;
1169
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001170 ccr = p->dma_read(CCR, ch);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001171 ccr &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001172 p->dma_write(ccr, CCR, ch);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001173 dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
1174 }
1175 }
Tony Lindgren7ff879d2006-06-26 16:16:15 -07001176 if (unlikely(status & OMAP2_DMA_SECURE_ERR_IRQ))
1177 printk(KERN_INFO "DMA secure error with device %d\n",
1178 dma_chan[ch].dev_id);
1179 if (unlikely(status & OMAP2_DMA_MISALIGNED_ERR_IRQ))
1180 printk(KERN_INFO "DMA misaligned error with device %d\n",
1181 dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001182
Adrian Hunter4fb699b2010-11-24 13:23:21 +02001183 p->dma_write(status, CSR, ch);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001184 p->dma_write(1 << ch, IRQSTATUS_L0, ch);
Mathias Nymane860e6d2010-10-25 14:35:24 +00001185 /* read back the register to flush the write */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001186 p->dma_read(IRQSTATUS_L0, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001187
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001188 /* If the ch is not chained then chain_id will be -1 */
1189 if (dma_chan[ch].chain_id != -1) {
1190 int chain_id = dma_chan[ch].chain_id;
1191 dma_chan[ch].state = DMA_CH_NOTSTARTED;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001192 if (p->dma_read(CLNK_CTRL, ch) & (1 << 15))
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001193 dma_chan[dma_chan[ch].next_linked_ch].state =
1194 DMA_CH_STARTED;
1195 if (dma_linked_lch[chain_id].chain_mode ==
1196 OMAP_DMA_DYNAMIC_CHAIN)
1197 disable_lnk(ch);
1198
1199 if (!OMAP_DMA_CHAIN_QEMPTY(chain_id))
1200 OMAP_DMA_CHAIN_INCQHEAD(chain_id);
1201
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001202 status = p->dma_read(CSR, ch);
Adrian Hunter4fb699b2010-11-24 13:23:21 +02001203 p->dma_write(status, CSR, ch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001204 }
1205
Jarkko Nikula538528d2008-02-13 11:47:29 +02001206 if (likely(dma_chan[ch].callback != NULL))
1207 dma_chan[ch].callback(ch, status, dma_chan[ch].data);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001208
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001209 return 0;
1210}
1211
1212/* STATUS register count is from 1-32 while our is 0-31 */
Linus Torvalds0cd61b62006-10-06 10:53:39 -07001213static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001214{
Santosh Shilimkar52176e72009-03-23 18:07:49 -07001215 u32 val, enable_reg;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001216 int i;
1217
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001218 val = p->dma_read(IRQSTATUS_L0, 0);
Juha Yrjola31513692006-12-06 17:13:47 -08001219 if (val == 0) {
1220 if (printk_ratelimit())
1221 printk(KERN_WARNING "Spurious DMA IRQ\n");
1222 return IRQ_HANDLED;
1223 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001224 enable_reg = p->dma_read(IRQENABLE_L0, 0);
Santosh Shilimkar52176e72009-03-23 18:07:49 -07001225 val &= enable_reg; /* Dispatch only relevant interrupts */
Tony Lindgren4d963722008-07-03 12:24:31 +03001226 for (i = 0; i < dma_lch_count && val != 0; i++) {
Juha Yrjola31513692006-12-06 17:13:47 -08001227 if (val & 1)
1228 omap2_dma_handle_ch(i);
1229 val >>= 1;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001230 }
1231
1232 return IRQ_HANDLED;
1233}
1234
1235static struct irqaction omap24xx_dma_irq = {
1236 .name = "DMA",
1237 .handler = omap2_dma_irq_handler,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001238};
1239
1240#else
1241static struct irqaction omap24xx_dma_irq;
1242#endif
1243
1244/*----------------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001245
Tony Lindgren9ce24822014-05-16 14:05:35 -07001246/*
1247 * Note that we are currently using only IRQENABLE_L0 and L1.
1248 * As the DSP may be using IRQENABLE_L2 and L3, let's not
1249 * touch those for now.
1250 */
Tero Kristof2d11852008-08-28 13:13:31 +00001251void omap_dma_global_context_save(void)
1252{
1253 omap_dma_global_context.dma_irqenable_l0 =
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001254 p->dma_read(IRQENABLE_L0, 0);
Tony Lindgren9ce24822014-05-16 14:05:35 -07001255 omap_dma_global_context.dma_irqenable_l1 =
1256 p->dma_read(IRQENABLE_L1, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00001257 omap_dma_global_context.dma_ocp_sysconfig =
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001258 p->dma_read(OCP_SYSCONFIG, 0);
1259 omap_dma_global_context.dma_gcr = p->dma_read(GCR, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00001260}
1261
1262void omap_dma_global_context_restore(void)
1263{
Aaro Koskinenbf07c9f2009-05-20 16:58:30 +03001264 int ch;
1265
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001266 p->dma_write(omap_dma_global_context.dma_gcr, GCR, 0);
1267 p->dma_write(omap_dma_global_context.dma_ocp_sysconfig,
G, Manjunath Kondaiaha4c537c72010-12-20 18:27:17 -08001268 OCP_SYSCONFIG, 0);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001269 p->dma_write(omap_dma_global_context.dma_irqenable_l0,
G, Manjunath Kondaiaha4c537c72010-12-20 18:27:17 -08001270 IRQENABLE_L0, 0);
Tony Lindgren9ce24822014-05-16 14:05:35 -07001271 p->dma_write(omap_dma_global_context.dma_irqenable_l1,
1272 IRQENABLE_L1, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00001273
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001274 if (IS_DMA_ERRATA(DMA_ROMCODE_BUG))
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001275 p->dma_write(0x3 , IRQSTATUS_L0, 0);
Aaro Koskinenbf07c9f2009-05-20 16:58:30 +03001276
1277 for (ch = 0; ch < dma_chan_count; ch++)
1278 if (dma_chan[ch].dev_id != -1)
1279 omap_clear_dma(ch);
Tero Kristof2d11852008-08-28 13:13:31 +00001280}
1281
Russell King1b416c42013-11-02 13:00:03 +00001282struct omap_system_dma_plat_info *omap_get_plat_info(void)
1283{
1284 return p;
1285}
1286EXPORT_SYMBOL_GPL(omap_get_plat_info);
1287
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001288static int omap_system_dma_probe(struct platform_device *pdev)
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001289{
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001290 int ch, ret = 0;
1291 int dma_irq;
1292 char irq_name[4];
1293 int irq_rel;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001294
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001295 p = pdev->dev.platform_data;
1296 if (!p) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001297 dev_err(&pdev->dev,
1298 "%s: System DMA initialized without platform data\n",
1299 __func__);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001300 return -EINVAL;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001301 }
1302
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001303 d = p->dma_attr;
1304 errata = p->errata;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001305
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001306 if ((d->dev_caps & RESERVE_CHANNEL) && omap_dma_reserve_channels
Chen Gange78f96062013-01-11 13:39:18 +08001307 && (omap_dma_reserve_channels < d->lch_count))
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001308 d->lch_count = omap_dma_reserve_channels;
Santosh Shilimkar2263f022009-03-23 18:07:48 -07001309
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001310 dma_lch_count = d->lch_count;
1311 dma_chan_count = dma_lch_count;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001312 enable_1510_mode = d->dev_caps & ENABLE_1510_MODE;
Tony Lindgren4d963722008-07-03 12:24:31 +03001313
Russell King9834f812013-11-08 18:10:42 +00001314 dma_chan = devm_kcalloc(&pdev->dev, dma_lch_count,
Markus Elfring16e7ea52017-10-03 20:46:48 +02001315 sizeof(*dma_chan), GFP_KERNEL);
Markus Elfringd6799502017-10-03 13:10:26 +02001316 if (!dma_chan)
Russell King9834f812013-11-08 18:10:42 +00001317 return -ENOMEM;
Russell King9834f812013-11-08 18:10:42 +00001318
Tony Lindgren82809602012-10-30 11:03:22 -07001319 if (dma_omap2plus()) {
Markus Elfring738c9852017-10-03 21:07:33 +02001320 dma_linked_lch = kcalloc(dma_lch_count,
1321 sizeof(*dma_linked_lch),
1322 GFP_KERNEL);
Tony Lindgren4d963722008-07-03 12:24:31 +03001323 if (!dma_linked_lch) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001324 ret = -ENOMEM;
1325 goto exit_dma_lch_fail;
Tony Lindgren4d963722008-07-03 12:24:31 +03001326 }
1327 }
1328
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001329 spin_lock_init(&dma_chan_lock);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001330 for (ch = 0; ch < dma_chan_count; ch++) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001331 omap_clear_dma(ch);
Tony Lindgren82809602012-10-30 11:03:22 -07001332 if (dma_omap2plus())
Mika Westerbergada8d4a2010-05-14 12:05:25 -07001333 omap2_disable_irq_lch(ch);
1334
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001335 dma_chan[ch].dev_id = -1;
1336 dma_chan[ch].next_lch = -1;
1337
1338 if (ch >= 6 && enable_1510_mode)
1339 continue;
1340
Tony Lindgren82809602012-10-30 11:03:22 -07001341 if (dma_omap1()) {
Tony Lindgren97b7f712008-07-03 12:24:37 +03001342 /*
1343 * request_irq() doesn't like dev_id (ie. ch) being
1344 * zero, so we have to kludge around this.
1345 */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001346 sprintf(&irq_name[0], "%d", ch);
1347 dma_irq = platform_get_irq_byname(pdev, irq_name);
1348
1349 if (dma_irq < 0) {
1350 ret = dma_irq;
1351 goto exit_dma_irq_fail;
1352 }
1353
1354 /* INT_DMA_LCD is handled in lcd_dma.c */
1355 if (dma_irq == INT_DMA_LCD)
1356 continue;
1357
1358 ret = request_irq(dma_irq,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001359 omap1_dma_irq_handler, 0, "DMA",
1360 (void *) (ch + 1));
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001361 if (ret != 0)
1362 goto exit_dma_irq_fail;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001363 }
1364 }
1365
Tony Lindgren82809602012-10-30 11:03:22 -07001366 if (d->dev_caps & IS_RW_PRIORITY)
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001367 omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE,
1368 DMA_DEFAULT_FIFO_DEPTH, 0);
1369
Nishanth Menon76be4a52014-06-12 17:15:22 +05301370 if (dma_omap2plus() && !(d->dev_caps & DMA_ENGINE_HANDLE_IRQ)) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001371 strcpy(irq_name, "0");
1372 dma_irq = platform_get_irq_byname(pdev, irq_name);
1373 if (dma_irq < 0) {
1374 dev_err(&pdev->dev, "failed: request IRQ %d", dma_irq);
Wei Yongjun94b1d612013-07-16 20:10:46 +08001375 ret = dma_irq;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001376 goto exit_dma_lch_fail;
1377 }
1378 ret = setup_irq(dma_irq, &omap24xx_dma_irq);
1379 if (ret) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001380 dev_err(&pdev->dev, "set_up failed for IRQ %d for DMA (error %d)\n",
1381 dma_irq, ret);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001382 goto exit_dma_lch_fail;
Kalle Jokiniemiba50ea72009-03-26 15:59:00 +02001383 }
Kalle Jokiniemiaecedb92009-06-23 13:30:24 +03001384 }
1385
Tony Lindgren82809602012-10-30 11:03:22 -07001386 /* reserve dma channels 0 and 1 in high security devices on 34xx */
1387 if (d->dev_caps & HS_CHANNELS_RESERVED) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001388 pr_info("Reserving DMA channels 0 and 1 for HS ROM code\n");
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001389 dma_chan[0].dev_id = 0;
1390 dma_chan[1].dev_id = 1;
1391 }
1392 p->show_dma_caps();
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001393 return 0;
Tony Lindgren7e9bf842009-10-19 15:25:15 -07001394
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001395exit_dma_irq_fail:
Paul Walmsley7852ec02012-07-26 00:54:26 -06001396 dev_err(&pdev->dev, "unable to request IRQ %d for DMA (error %d)\n",
1397 dma_irq, ret);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001398 for (irq_rel = 0; irq_rel < ch; irq_rel++) {
1399 dma_irq = platform_get_irq(pdev, irq_rel);
1400 free_irq(dma_irq, (void *)(irq_rel + 1));
1401 }
1402
1403exit_dma_lch_fail:
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001404 return ret;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001405}
1406
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001407static int omap_system_dma_remove(struct platform_device *pdev)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001408{
1409 int dma_irq;
1410
Tony Lindgren82809602012-10-30 11:03:22 -07001411 if (dma_omap2plus()) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001412 char irq_name[4];
1413 strcpy(irq_name, "0");
1414 dma_irq = platform_get_irq_byname(pdev, irq_name);
Nishanth Menon76be4a52014-06-12 17:15:22 +05301415 if (dma_irq >= 0)
1416 remove_irq(dma_irq, &omap24xx_dma_irq);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001417 } else {
1418 int irq_rel = 0;
1419 for ( ; irq_rel < dma_chan_count; irq_rel++) {
1420 dma_irq = platform_get_irq(pdev, irq_rel);
1421 free_irq(dma_irq, (void *)(irq_rel + 1));
1422 }
1423 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001424 return 0;
1425}
1426
1427static struct platform_driver omap_system_dma_driver = {
1428 .probe = omap_system_dma_probe,
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001429 .remove = omap_system_dma_remove,
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001430 .driver = {
1431 .name = "omap_dma_system"
1432 },
1433};
1434
1435static int __init omap_system_dma_init(void)
1436{
1437 return platform_driver_register(&omap_system_dma_driver);
1438}
1439arch_initcall(omap_system_dma_init);
1440
1441static void __exit omap_system_dma_exit(void)
1442{
1443 platform_driver_unregister(&omap_system_dma_driver);
1444}
1445
1446MODULE_DESCRIPTION("OMAP SYSTEM DMA DRIVER");
1447MODULE_LICENSE("GPL");
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001448MODULE_AUTHOR("Texas Instruments Inc");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001449
Santosh Shilimkar2263f022009-03-23 18:07:48 -07001450/*
1451 * Reserve the omap SDMA channels using cmdline bootarg
1452 * "omap_dma_reserve_ch=". The valid range is 1 to 32
1453 */
1454static int __init omap_dma_cmdline_reserve_ch(char *str)
1455{
1456 if (get_option(&str, &omap_dma_reserve_channels) != 1)
1457 omap_dma_reserve_channels = 0;
1458 return 1;
1459}
1460
1461__setup("omap_dma_reserve_ch=", omap_dma_cmdline_reserve_ch);
1462
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001463