blob: 1e460b4ee3b9d591a560c8145226fe067f8b3da2 [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
Tony Lindgren685e2d02015-05-20 09:01:21 -070041#ifdef CONFIG_ARCH_OMAP1
42#include <mach/soc.h>
43#endif
44
Paul Walmsleybc4d8b52012-04-13 06:34:30 -060045/*
46 * MAX_LOGICAL_DMA_CH_COUNT: the maximum number of logical DMA
47 * channels that an instance of the SDMA IP block can support. Used
48 * to size arrays. (The actual maximum on a particular SoC may be less
49 * than this -- for example, OMAP1 SDMA instances only support 17 logical
50 * DMA channels.)
51 */
52#define MAX_LOGICAL_DMA_CH_COUNT 32
53
Anand Gadiyarf8151e52007-12-01 12:14:11 -080054#undef DEBUG
55
56#ifndef CONFIG_ARCH_OMAP1
57enum { DMA_CH_ALLOC_DONE, DMA_CH_PARAMS_SET_DONE, DMA_CH_STARTED,
58 DMA_CH_QUEUED, DMA_CH_NOTSTARTED, DMA_CH_PAUSED, DMA_CH_LINK_ENABLED
59};
60
61enum { DMA_CHAIN_STARTED, DMA_CHAIN_NOTSTARTED };
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000062#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010063
Tony Lindgren97b7f712008-07-03 12:24:37 +030064#define OMAP_DMA_ACTIVE 0x01
Adrian Hunter4fb699b2010-11-24 13:23:21 +020065#define OMAP2_DMA_CSR_CLEAR_MASK 0xffffffff
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010066
Tony Lindgren97b7f712008-07-03 12:24:37 +030067#define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010068
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -080069static struct omap_system_dma_plat_info *p;
70static struct omap_dma_dev_attr *d;
Tony Lindgren175655b2014-09-16 17:36:28 -070071static void omap_clear_dma(int lch);
72static int omap_dma_set_prio_lch(int lch, unsigned char read_prio,
73 unsigned char write_prio);
Tony Lindgren97b7f712008-07-03 12:24:37 +030074static int enable_1510_mode;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -080075static u32 errata;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010076
Tero Kristof2d11852008-08-28 13:13:31 +000077static struct omap_dma_global_context_registers {
78 u32 dma_irqenable_l0;
Tony Lindgren9ce24822014-05-16 14:05:35 -070079 u32 dma_irqenable_l1;
Tero Kristof2d11852008-08-28 13:13:31 +000080 u32 dma_ocp_sysconfig;
81 u32 dma_gcr;
82} omap_dma_global_context;
83
Anand Gadiyarf8151e52007-12-01 12:14:11 -080084struct dma_link_info {
85 int *linked_dmach_q;
86 int no_of_lchs_linked;
87
88 int q_count;
89 int q_tail;
90 int q_head;
91
92 int chain_state;
93 int chain_mode;
94
95};
96
Tony Lindgren4d963722008-07-03 12:24:31 +030097static struct dma_link_info *dma_linked_lch;
98
99#ifndef CONFIG_ARCH_OMAP1
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800100
101/* Chain handling macros */
102#define OMAP_DMA_CHAIN_QINIT(chain_id) \
103 do { \
104 dma_linked_lch[chain_id].q_head = \
105 dma_linked_lch[chain_id].q_tail = \
106 dma_linked_lch[chain_id].q_count = 0; \
107 } while (0)
108#define OMAP_DMA_CHAIN_QFULL(chain_id) \
109 (dma_linked_lch[chain_id].no_of_lchs_linked == \
110 dma_linked_lch[chain_id].q_count)
111#define OMAP_DMA_CHAIN_QLAST(chain_id) \
112 do { \
113 ((dma_linked_lch[chain_id].no_of_lchs_linked-1) == \
114 dma_linked_lch[chain_id].q_count) \
115 } while (0)
116#define OMAP_DMA_CHAIN_QEMPTY(chain_id) \
117 (0 == dma_linked_lch[chain_id].q_count)
118#define __OMAP_DMA_CHAIN_INCQ(end) \
119 ((end) = ((end)+1) % dma_linked_lch[chain_id].no_of_lchs_linked)
120#define OMAP_DMA_CHAIN_INCQHEAD(chain_id) \
121 do { \
122 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_head); \
123 dma_linked_lch[chain_id].q_count--; \
124 } while (0)
125
126#define OMAP_DMA_CHAIN_INCQTAIL(chain_id) \
127 do { \
128 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_tail); \
129 dma_linked_lch[chain_id].q_count++; \
130 } while (0)
131#endif
Tony Lindgren4d963722008-07-03 12:24:31 +0300132
133static int dma_lch_count;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100134static int dma_chan_count;
Santosh Shilimkar2263f022009-03-23 18:07:48 -0700135static int omap_dma_reserve_channels;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100136
137static spinlock_t dma_chan_lock;
Tony Lindgren4d963722008-07-03 12:24:31 +0300138static struct omap_dma_lch *dma_chan;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100139
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800140static inline void disable_lnk(int lch);
141static void omap_disable_channel_irq(int lch);
142static inline void omap_enable_channel_irq(int lch);
143
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000144#define REVISIT_24XX() printk(KERN_ERR "FIXME: no %s on 24xx\n", \
Harvey Harrison8e86f422008-03-04 15:08:02 -0800145 __func__);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000146
147#ifdef CONFIG_ARCH_OMAP15XX
148/* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */
Aaro Koskinenc7767582011-01-27 16:39:43 -0800149static int omap_dma_in_1510_mode(void)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000150{
151 return enable_1510_mode;
152}
153#else
154#define omap_dma_in_1510_mode() 0
155#endif
156
157#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100158static inline void set_gdma_dev(int req, int dev)
159{
160 u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
161 int shift = ((req - 1) % 5) * 6;
162 u32 l;
163
164 l = omap_readl(reg);
165 l &= ~(0x3f << shift);
166 l |= (dev - 1) << shift;
167 omap_writel(l, reg);
168}
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000169#else
170#define set_gdma_dev(req, dev) do {} while (0)
Tony Lindgren2c799ce2012-02-24 10:34:35 -0800171#define omap_readl(reg) 0
172#define omap_writel(val, reg) do {} while (0)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000173#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100174
Tony Lindgren54b693d2012-10-02 13:39:28 -0700175#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300176void omap_set_dma_priority(int lch, int dst_port, int priority)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100177{
178 unsigned long reg;
179 u32 l;
180
Tony Lindgren82809602012-10-30 11:03:22 -0700181 if (dma_omap1()) {
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300182 switch (dst_port) {
183 case OMAP_DMA_PORT_OCP_T1: /* FFFECC00 */
184 reg = OMAP_TC_OCPT1_PRIOR;
185 break;
186 case OMAP_DMA_PORT_OCP_T2: /* FFFECCD0 */
187 reg = OMAP_TC_OCPT2_PRIOR;
188 break;
189 case OMAP_DMA_PORT_EMIFF: /* FFFECC08 */
190 reg = OMAP_TC_EMIFF_PRIOR;
191 break;
192 case OMAP_DMA_PORT_EMIFS: /* FFFECC04 */
193 reg = OMAP_TC_EMIFS_PRIOR;
194 break;
195 default:
196 BUG();
197 return;
198 }
199 l = omap_readl(reg);
200 l &= ~(0xf << 8);
201 l |= (priority & 0xf) << 8;
202 omap_writel(l, reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100203 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100204}
Tony Lindgren54b693d2012-10-02 13:39:28 -0700205#endif
206
207#ifdef CONFIG_ARCH_OMAP2PLUS
208void omap_set_dma_priority(int lch, int dst_port, int priority)
209{
210 u32 ccr;
211
212 ccr = p->dma_read(CCR, lch);
213 if (priority)
214 ccr |= (1 << 6);
215 else
216 ccr &= ~(1 << 6);
217 p->dma_write(ccr, CCR, lch);
218}
219#endif
Tony Lindgren97b7f712008-07-03 12:24:37 +0300220EXPORT_SYMBOL(omap_set_dma_priority);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100221
222void omap_set_dma_transfer_params(int lch, int data_type, int elem_count,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000223 int frame_count, int sync_mode,
224 int dma_trigger, int src_or_dst_synch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100225{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300226 u32 l;
227
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800228 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300229 l &= ~0x03;
230 l |= data_type;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800231 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100232
Tony Lindgren82809602012-10-30 11:03:22 -0700233 if (dma_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300234 u16 ccr;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100235
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800236 ccr = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300237 ccr &= ~(1 << 5);
238 if (sync_mode == OMAP_DMA_SYNC_FRAME)
239 ccr |= 1 << 5;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800240 p->dma_write(ccr, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300241
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800242 ccr = p->dma_read(CCR2, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300243 ccr &= ~(1 << 2);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000244 if (sync_mode == OMAP_DMA_SYNC_BLOCK)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300245 ccr |= 1 << 2;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800246 p->dma_write(ccr, CCR2, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000247 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100248
Tony Lindgren82809602012-10-30 11:03:22 -0700249 if (dma_omap2plus() && dma_trigger) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300250 u32 val;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100251
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800252 val = p->dma_read(CCR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100253
Anand Gadiyar4b3cf442009-01-15 13:09:53 +0200254 /* DMA_SYNCHRO_CONTROL_UPPER depends on the channel number */
Samu Onkalo72a11792010-08-02 14:21:40 +0300255 val &= ~((1 << 23) | (3 << 19) | 0x1f);
Anand Gadiyar4b3cf442009-01-15 13:09:53 +0200256 val |= (dma_trigger & ~0x1f) << 14;
257 val |= dma_trigger & 0x1f;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000258
259 if (sync_mode & OMAP_DMA_SYNC_FRAME)
260 val |= 1 << 5;
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700261 else
262 val &= ~(1 << 5);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000263
264 if (sync_mode & OMAP_DMA_SYNC_BLOCK)
265 val |= 1 << 18;
Peter Ujfalusieca9e562006-06-26 16:16:06 -0700266 else
267 val &= ~(1 << 18);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000268
Samu Onkalo72a11792010-08-02 14:21:40 +0300269 if (src_or_dst_synch == OMAP_DMA_DST_SYNC_PREFETCH) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000270 val &= ~(1 << 24); /* dest synch */
Samu Onkalo72a11792010-08-02 14:21:40 +0300271 val |= (1 << 23); /* Prefetch */
272 } else if (src_or_dst_synch) {
273 val |= 1 << 24; /* source synch */
274 } else {
275 val &= ~(1 << 24); /* dest synch */
276 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800277 p->dma_write(val, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000278 }
279
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800280 p->dma_write(elem_count, CEN, lch);
281 p->dma_write(frame_count, CFN, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100282}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300283EXPORT_SYMBOL(omap_set_dma_transfer_params);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000284
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300285void omap_set_dma_write_mode(int lch, enum omap_dma_write_mode mode)
286{
Tony Lindgren82809602012-10-30 11:03:22 -0700287 if (dma_omap2plus()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300288 u32 csdp;
289
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800290 csdp = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300291 csdp &= ~(0x3 << 16);
292 csdp |= (mode << 16);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800293 p->dma_write(csdp, CSDP, lch);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300294 }
295}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300296EXPORT_SYMBOL(omap_set_dma_write_mode);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300297
Tony Lindgren0499bde2008-07-03 12:24:36 +0300298void omap_set_dma_channel_mode(int lch, enum omap_dma_channel_mode mode)
299{
Tony Lindgren82809602012-10-30 11:03:22 -0700300 if (dma_omap1() && !dma_omap15xx()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300301 u32 l;
302
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800303 l = p->dma_read(LCH_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300304 l &= ~0x7;
305 l |= mode;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800306 p->dma_write(l, LCH_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300307 }
308}
309EXPORT_SYMBOL(omap_set_dma_channel_mode);
310
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000311/* Note that src_port is only for omap1 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100312void omap_set_dma_src_params(int lch, int src_port, int src_amode,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000313 unsigned long src_start,
314 int src_ei, int src_fi)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100315{
Tony Lindgren97b7f712008-07-03 12:24:37 +0300316 u32 l;
317
Tony Lindgren82809602012-10-30 11:03:22 -0700318 if (dma_omap1()) {
Tony Lindgren0499bde2008-07-03 12:24:36 +0300319 u16 w;
320
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800321 w = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300322 w &= ~(0x1f << 2);
323 w |= src_port << 2;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800324 p->dma_write(w, CSDP, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300325 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300326
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800327 l = p->dma_read(CCR, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300328 l &= ~(0x03 << 12);
329 l |= src_amode << 12;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800330 p->dma_write(l, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300331
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800332 p->dma_write(src_start, CSSA, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100333
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800334 p->dma_write(src_ei, CSEI, lch);
335 p->dma_write(src_fi, CSFI, lch);
Tony Lindgren97b7f712008-07-03 12:24:37 +0300336}
337EXPORT_SYMBOL(omap_set_dma_src_params);
338
339void omap_set_dma_params(int lch, struct omap_dma_channel_params *params)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000340{
341 omap_set_dma_transfer_params(lch, params->data_type,
342 params->elem_count, params->frame_count,
343 params->sync_mode, params->trigger,
344 params->src_or_dst_synch);
345 omap_set_dma_src_params(lch, params->src_port,
346 params->src_amode, params->src_start,
347 params->src_ei, params->src_fi);
348
349 omap_set_dma_dest_params(lch, params->dst_port,
350 params->dst_amode, params->dst_start,
351 params->dst_ei, params->dst_fi);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800352 if (params->read_prio || params->write_prio)
353 omap_dma_set_prio_lch(lch, params->read_prio,
354 params->write_prio);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100355}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300356EXPORT_SYMBOL(omap_set_dma_params);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100357
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100358void omap_set_dma_src_data_pack(int lch, int enable)
359{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300360 u32 l;
361
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800362 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300363 l &= ~(1 << 6);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000364 if (enable)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300365 l |= (1 << 6);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800366 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100367}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300368EXPORT_SYMBOL(omap_set_dma_src_data_pack);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100369
370void omap_set_dma_src_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
371{
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700372 unsigned int burst = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300373 u32 l;
374
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800375 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300376 l &= ~(0x03 << 7);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100377
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100378 switch (burst_mode) {
379 case OMAP_DMA_DATA_BURST_DIS:
380 break;
381 case OMAP_DMA_DATA_BURST_4:
Tony Lindgren82809602012-10-30 11:03:22 -0700382 if (dma_omap2plus())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700383 burst = 0x1;
384 else
385 burst = 0x2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100386 break;
387 case OMAP_DMA_DATA_BURST_8:
Tony Lindgren82809602012-10-30 11:03:22 -0700388 if (dma_omap2plus()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700389 burst = 0x2;
390 break;
391 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700392 /*
393 * not supported by current hardware on OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100394 * w |= (0x03 << 7);
395 * fall through
396 */
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700397 case OMAP_DMA_DATA_BURST_16:
Tony Lindgren82809602012-10-30 11:03:22 -0700398 if (dma_omap2plus()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700399 burst = 0x3;
400 break;
401 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700402 /*
403 * OMAP1 don't support burst 16
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700404 * fall through
405 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100406 default:
407 BUG();
408 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300409
410 l |= (burst << 7);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800411 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100412}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300413EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100414
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000415/* Note that dest_port is only for OMAP1 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100416void omap_set_dma_dest_params(int lch, int dest_port, int dest_amode,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000417 unsigned long dest_start,
418 int dst_ei, int dst_fi)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100419{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300420 u32 l;
421
Tony Lindgren82809602012-10-30 11:03:22 -0700422 if (dma_omap1()) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800423 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300424 l &= ~(0x1f << 9);
425 l |= dest_port << 9;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800426 p->dma_write(l, CSDP, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000427 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100428
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800429 l = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300430 l &= ~(0x03 << 14);
431 l |= dest_amode << 14;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800432 p->dma_write(l, CCR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100433
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800434 p->dma_write(dest_start, CDSA, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100435
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800436 p->dma_write(dst_ei, CDEI, lch);
437 p->dma_write(dst_fi, CDFI, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100438}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300439EXPORT_SYMBOL(omap_set_dma_dest_params);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100440
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100441void omap_set_dma_dest_data_pack(int lch, int enable)
442{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300443 u32 l;
444
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800445 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300446 l &= ~(1 << 13);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000447 if (enable)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300448 l |= 1 << 13;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800449 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100450}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300451EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100452
453void omap_set_dma_dest_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
454{
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700455 unsigned int burst = 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300456 u32 l;
457
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800458 l = p->dma_read(CSDP, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300459 l &= ~(0x03 << 14);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100460
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100461 switch (burst_mode) {
462 case OMAP_DMA_DATA_BURST_DIS:
463 break;
464 case OMAP_DMA_DATA_BURST_4:
Tony Lindgren82809602012-10-30 11:03:22 -0700465 if (dma_omap2plus())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700466 burst = 0x1;
467 else
468 burst = 0x2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100469 break;
470 case OMAP_DMA_DATA_BURST_8:
Tony Lindgren82809602012-10-30 11:03:22 -0700471 if (dma_omap2plus())
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700472 burst = 0x2;
473 else
474 burst = 0x3;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100475 break;
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700476 case OMAP_DMA_DATA_BURST_16:
Tony Lindgren82809602012-10-30 11:03:22 -0700477 if (dma_omap2plus()) {
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700478 burst = 0x3;
479 break;
480 }
manjugk manjugkea221a62010-05-14 12:05:25 -0700481 /*
482 * OMAP1 don't support burst 16
Kyungmin Park6dc3c8f2006-06-26 16:16:14 -0700483 * fall through
484 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100485 default:
486 printk(KERN_ERR "Invalid DMA burst mode\n");
487 BUG();
488 return;
489 }
Tony Lindgren0499bde2008-07-03 12:24:36 +0300490 l |= (burst << 14);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800491 p->dma_write(l, CSDP, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100492}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300493EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100494
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000495static inline void omap_enable_channel_irq(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100496{
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700497 /* Clear CSR */
Tony Lindgren82809602012-10-30 11:03:22 -0700498 if (dma_omap1())
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700499 p->dma_read(CSR, lch);
500 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800501 p->dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000502
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100503 /* Enable some nice interrupts. */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800504 p->dma_write(dma_chan[lch].enabled_irqs, CICR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100505}
506
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700507static inline void omap_disable_channel_irq(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100508{
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700509 /* disable channel interrupts */
510 p->dma_write(0, CICR, lch);
511 /* Clear CSR */
Tony Lindgren82809602012-10-30 11:03:22 -0700512 if (dma_omap1())
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700513 p->dma_read(CSR, lch);
514 else
515 p->dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100516}
517
518void omap_enable_dma_irq(int lch, u16 bits)
519{
520 dma_chan[lch].enabled_irqs |= bits;
521}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300522EXPORT_SYMBOL(omap_enable_dma_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100523
524void omap_disable_dma_irq(int lch, u16 bits)
525{
526 dma_chan[lch].enabled_irqs &= ~bits;
527}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300528EXPORT_SYMBOL(omap_disable_dma_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100529
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000530static inline void enable_lnk(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100531{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300532 u32 l;
533
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800534 l = p->dma_read(CLNK_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300535
Tony Lindgren82809602012-10-30 11:03:22 -0700536 if (dma_omap1())
Tony Lindgren0499bde2008-07-03 12:24:36 +0300537 l &= ~(1 << 14);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100538
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000539 /* Set the ENABLE_LNK bits */
540 if (dma_chan[lch].next_lch != -1)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300541 l = dma_chan[lch].next_lch | (1 << 15);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800542
543#ifndef CONFIG_ARCH_OMAP1
Tony Lindgren82809602012-10-30 11:03:22 -0700544 if (dma_omap2plus())
Tony Lindgren97b7f712008-07-03 12:24:37 +0300545 if (dma_chan[lch].next_linked_ch != -1)
546 l = dma_chan[lch].next_linked_ch | (1 << 15);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800547#endif
Tony Lindgren0499bde2008-07-03 12:24:36 +0300548
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800549 p->dma_write(l, CLNK_CTRL, lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100550}
551
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000552static inline void disable_lnk(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100553{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300554 u32 l;
555
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800556 l = p->dma_read(CLNK_CTRL, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300557
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000558 /* Disable interrupts */
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700559 omap_disable_channel_irq(lch);
560
Tony Lindgren82809602012-10-30 11:03:22 -0700561 if (dma_omap1()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000562 /* Set the STOP_LNK bit */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300563 l |= 1 << 14;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100564 }
565
Tony Lindgren82809602012-10-30 11:03:22 -0700566 if (dma_omap2plus()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000567 /* Clear the ENABLE_LNK bit */
Tony Lindgren0499bde2008-07-03 12:24:36 +0300568 l &= ~(1 << 15);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000569 }
570
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800571 p->dma_write(l, CLNK_CTRL, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000572 dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
573}
574
575static inline void omap2_enable_irq_lch(int lch)
576{
577 u32 val;
Tao Huee907322009-11-10 18:55:17 -0800578 unsigned long flags;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000579
Tony Lindgren82809602012-10-30 11:03:22 -0700580 if (dma_omap1())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000581 return;
582
Tao Huee907322009-11-10 18:55:17 -0800583 spin_lock_irqsave(&dma_chan_lock, flags);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700584 /* clear IRQ STATUS */
585 p->dma_write(1 << lch, IRQSTATUS_L0, lch);
586 /* Enable interrupt */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800587 val = p->dma_read(IRQENABLE_L0, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000588 val |= 1 << lch;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800589 p->dma_write(val, IRQENABLE_L0, lch);
Tao Huee907322009-11-10 18:55:17 -0800590 spin_unlock_irqrestore(&dma_chan_lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100591}
592
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700593static inline void omap2_disable_irq_lch(int lch)
594{
595 u32 val;
596 unsigned long flags;
597
Tony Lindgren82809602012-10-30 11:03:22 -0700598 if (dma_omap1())
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700599 return;
600
601 spin_lock_irqsave(&dma_chan_lock, flags);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700602 /* Disable interrupt */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800603 val = p->dma_read(IRQENABLE_L0, lch);
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700604 val &= ~(1 << lch);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800605 p->dma_write(val, IRQENABLE_L0, lch);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700606 /* clear IRQ STATUS */
607 p->dma_write(1 << lch, IRQSTATUS_L0, lch);
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700608 spin_unlock_irqrestore(&dma_chan_lock, flags);
609}
610
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100611int omap_request_dma(int dev_id, const char *dev_name,
Tony Lindgren97b7f712008-07-03 12:24:37 +0300612 void (*callback)(int lch, u16 ch_status, void *data),
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100613 void *data, int *dma_ch_out)
614{
615 int ch, free_ch = -1;
616 unsigned long flags;
617 struct omap_dma_lch *chan;
618
Russell King5c65c362014-06-07 10:47:36 +0100619 WARN(strcmp(dev_name, "DMA engine"), "Using deprecated platform DMA API - please update to DMA engine");
620
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100621 spin_lock_irqsave(&dma_chan_lock, flags);
622 for (ch = 0; ch < dma_chan_count; ch++) {
623 if (free_ch == -1 && dma_chan[ch].dev_id == -1) {
624 free_ch = ch;
R Sricharan03a6d4a2013-06-13 19:47:09 +0530625 /* Exit after first free channel found */
626 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100627 }
628 }
629 if (free_ch == -1) {
630 spin_unlock_irqrestore(&dma_chan_lock, flags);
631 return -EBUSY;
632 }
633 chan = dma_chan + free_ch;
634 chan->dev_id = dev_id;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000635
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800636 if (p->clear_lch_regs)
637 p->clear_lch_regs(free_ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000638
Tony Lindgren82809602012-10-30 11:03:22 -0700639 if (dma_omap2plus())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000640 omap_clear_dma(free_ch);
641
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100642 spin_unlock_irqrestore(&dma_chan_lock, flags);
643
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100644 chan->dev_name = dev_name;
645 chan->callback = callback;
646 chan->data = data;
Jarkko Nikulaa92fda12009-01-29 08:57:12 -0800647 chan->flags = 0;
Tony Lindgren97b7f712008-07-03 12:24:37 +0300648
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800649#ifndef CONFIG_ARCH_OMAP1
Tony Lindgren82809602012-10-30 11:03:22 -0700650 if (dma_omap2plus()) {
Tony Lindgren97b7f712008-07-03 12:24:37 +0300651 chan->chain_id = -1;
652 chan->next_linked_ch = -1;
653 }
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800654#endif
Tony Lindgren97b7f712008-07-03 12:24:37 +0300655
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700656 chan->enabled_irqs = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000657
Tony Lindgren82809602012-10-30 11:03:22 -0700658 if (dma_omap1())
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700659 chan->enabled_irqs |= OMAP1_DMA_TOUT_IRQ;
Tony Lindgren82809602012-10-30 11:03:22 -0700660 else if (dma_omap2plus())
Tony Lindgren7ff879d2006-06-26 16:16:15 -0700661 chan->enabled_irqs |= OMAP2_DMA_MISALIGNED_ERR_IRQ |
662 OMAP2_DMA_TRANS_ERR_IRQ;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100663
Tony Lindgren82809602012-10-30 11:03:22 -0700664 if (dma_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100665 /* If the sync device is set, configure it dynamically. */
666 if (dev_id != 0) {
667 set_gdma_dev(free_ch + 1, dev_id);
668 dev_id = free_ch + 1;
669 }
Tony Lindgren97b7f712008-07-03 12:24:37 +0300670 /*
671 * Disable the 1510 compatibility mode and set the sync device
672 * id.
673 */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800674 p->dma_write(dev_id | (1 << 10), CCR, free_ch);
Tony Lindgren82809602012-10-30 11:03:22 -0700675 } else if (dma_omap1()) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800676 p->dma_write(dev_id, CCR, free_ch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100677 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000678
Tony Lindgren82809602012-10-30 11:03:22 -0700679 if (dma_omap2plus()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000680 omap_enable_channel_irq(free_ch);
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700681 omap2_enable_irq_lch(free_ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000682 }
683
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100684 *dma_ch_out = free_ch;
685
686 return 0;
687}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300688EXPORT_SYMBOL(omap_request_dma);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100689
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000690void omap_free_dma(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100691{
692 unsigned long flags;
693
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000694 if (dma_chan[lch].dev_id == -1) {
Tony Lindgren97b7f712008-07-03 12:24:37 +0300695 pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000696 lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100697 return;
698 }
Tony Lindgren97b7f712008-07-03 12:24:37 +0300699
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700700 /* Disable interrupt for logical channel */
Tony Lindgren82809602012-10-30 11:03:22 -0700701 if (dma_omap2plus())
Mika Westerbergada8d4a2010-05-14 12:05:25 -0700702 omap2_disable_irq_lch(lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000703
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700704 /* Disable all DMA interrupts for the channel. */
705 omap_disable_channel_irq(lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000706
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700707 /* Make sure the DMA transfer is stopped. */
708 p->dma_write(0, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000709
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700710 /* Clear registers */
Tony Lindgren82809602012-10-30 11:03:22 -0700711 if (dma_omap2plus())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000712 omap_clear_dma(lch);
Santosh Shilimkarda1b94e2009-04-23 11:10:40 -0700713
714 spin_lock_irqsave(&dma_chan_lock, flags);
715 dma_chan[lch].dev_id = -1;
716 dma_chan[lch].next_lch = -1;
717 dma_chan[lch].callback = NULL;
718 spin_unlock_irqrestore(&dma_chan_lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100719}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300720EXPORT_SYMBOL(omap_free_dma);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100721
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800722/**
723 * @brief omap_dma_set_global_params : Set global priority settings for dma
724 *
725 * @param arb_rate
726 * @param max_fifo_depth
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700727 * @param tparams - Number of threads to reserve : DMA_THREAD_RESERVE_NORM
728 * DMA_THREAD_RESERVE_ONET
729 * DMA_THREAD_RESERVE_TWOT
730 * DMA_THREAD_RESERVE_THREET
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800731 */
732void
733omap_dma_set_global_params(int arb_rate, int max_fifo_depth, int tparams)
734{
735 u32 reg;
736
Tony Lindgren82809602012-10-30 11:03:22 -0700737 if (dma_omap1()) {
Harvey Harrison8e86f422008-03-04 15:08:02 -0800738 printk(KERN_ERR "FIXME: no %s on 15xx/16xx\n", __func__);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800739 return;
740 }
741
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700742 if (max_fifo_depth == 0)
743 max_fifo_depth = 1;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800744 if (arb_rate == 0)
745 arb_rate = 1;
746
Anuj Aggarwal70cf6442009-10-14 09:56:34 -0700747 reg = 0xff & max_fifo_depth;
748 reg |= (0x3 & tparams) << 12;
749 reg |= (arb_rate & 0xff) << 16;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800750
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800751 p->dma_write(reg, GCR, 0);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800752}
753EXPORT_SYMBOL(omap_dma_set_global_params);
754
755/**
756 * @brief omap_dma_set_prio_lch : Set channel wise priority settings
757 *
758 * @param lch
759 * @param read_prio - Read priority
760 * @param write_prio - Write priority
761 * Both of the above can be set with one of the following values :
762 * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW
763 */
Tony Lindgren175655b2014-09-16 17:36:28 -0700764static int
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800765omap_dma_set_prio_lch(int lch, unsigned char read_prio,
766 unsigned char write_prio)
767{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300768 u32 l;
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800769
Tony Lindgren4d963722008-07-03 12:24:31 +0300770 if (unlikely((lch < 0 || lch >= dma_lch_count))) {
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800771 printk(KERN_ERR "Invalid channel id\n");
772 return -EINVAL;
773 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800774 l = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300775 l &= ~((1 << 6) | (1 << 26));
Tony Lindgren82809602012-10-30 11:03:22 -0700776 if (d->dev_caps & IS_RW_PRIORITY)
Tony Lindgren0499bde2008-07-03 12:24:36 +0300777 l |= ((read_prio & 0x1) << 6) | ((write_prio & 0x1) << 26);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800778 else
Tony Lindgren0499bde2008-07-03 12:24:36 +0300779 l |= ((read_prio & 0x1) << 6);
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800780
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800781 p->dma_write(l, CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300782
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800783 return 0;
784}
Tony Lindgren175655b2014-09-16 17:36:28 -0700785
Anand Gadiyarf8151e52007-12-01 12:14:11 -0800786
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000787/*
788 * Clears any DMA state so the DMA engine is ready to restart with new buffers
789 * through omap_start_dma(). Any buffers in flight are discarded.
790 */
Tony Lindgren175655b2014-09-16 17:36:28 -0700791static void omap_clear_dma(int lch)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100792{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000793 unsigned long flags;
794
795 local_irq_save(flags);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800796 p->clear_dma(lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000797 local_irq_restore(flags);
798}
799
800void omap_start_dma(int lch)
801{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300802 u32 l;
803
manjugk manjugk519e6162010-03-04 07:11:56 +0000804 /*
805 * The CPC/CDAC register needs to be initialized to zero
806 * before starting dma transfer.
807 */
Tony Lindgren82809602012-10-30 11:03:22 -0700808 if (dma_omap15xx())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800809 p->dma_write(0, CPC, lch);
manjugk manjugk519e6162010-03-04 07:11:56 +0000810 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800811 p->dma_write(0, CDAC, lch);
manjugk manjugk519e6162010-03-04 07:11:56 +0000812
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000813 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
814 int next_lch, cur_lch;
Paul Walmsleybc4d8b52012-04-13 06:34:30 -0600815 char dma_chan_link_map[MAX_LOGICAL_DMA_CH_COUNT];
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000816
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000817 /* Set the link register of the first channel */
818 enable_lnk(lch);
819
820 memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
R Sricharanf0a3ff22013-06-13 19:47:10 +0530821 dma_chan_link_map[lch] = 1;
822
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000823 cur_lch = dma_chan[lch].next_lch;
824 do {
825 next_lch = dma_chan[cur_lch].next_lch;
826
827 /* The loop case: we've been here already */
828 if (dma_chan_link_map[cur_lch])
829 break;
830 /* Mark the current channel */
831 dma_chan_link_map[cur_lch] = 1;
832
833 enable_lnk(cur_lch);
834 omap_enable_channel_irq(cur_lch);
835
836 cur_lch = next_lch;
837 } while (next_lch != -1);
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800838 } else if (IS_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS))
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800839 p->dma_write(lch, CLNK_CTRL, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000840
841 omap_enable_channel_irq(lch);
842
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800843 l = p->dma_read(CCR, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300844
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800845 if (IS_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING))
846 l |= OMAP_DMA_CCR_BUFFERING_DISABLE;
Tony Lindgren0499bde2008-07-03 12:24:36 +0300847 l |= OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800848
Russell King35453582012-04-14 18:57:10 +0100849 /*
850 * As dma_write() uses IO accessors which are weakly ordered, there
851 * is no guarantee that data in coherent DMA memory will be visible
852 * to the DMA device. Add a memory barrier here to ensure that any
853 * such data is visible prior to enabling DMA.
854 */
855 mb();
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800856 p->dma_write(l, CCR, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000857
858 dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
859}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300860EXPORT_SYMBOL(omap_start_dma);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000861
862void omap_stop_dma(int lch)
863{
Tony Lindgren0499bde2008-07-03 12:24:36 +0300864 u32 l;
865
Santosh Shilimkar9da65a92009-10-22 14:46:31 -0700866 /* Disable all interrupts on the channel */
Oleg Matcovschibedfb7a2012-05-15 14:35:08 -0700867 omap_disable_channel_irq(lch);
Santosh Shilimkar9da65a92009-10-22 14:46:31 -0700868
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800869 l = p->dma_read(CCR, lch);
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800870 if (IS_DMA_ERRATA(DMA_ERRATA_i541) &&
871 (l & OMAP_DMA_CCR_SEL_SRC_DST_SYNC)) {
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700872 int i = 0;
873 u32 sys_cf;
874
875 /* Configure No-Standby */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800876 l = p->dma_read(OCP_SYSCONFIG, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700877 sys_cf = l;
878 l &= ~DMA_SYSCONFIG_MIDLEMODE_MASK;
879 l |= DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_NO_IDLE);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800880 p->dma_write(l , OCP_SYSCONFIG, 0);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700881
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800882 l = p->dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700883 l &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800884 p->dma_write(l, CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700885
886 /* Wait for sDMA FIFO drain */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800887 l = p->dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700888 while (i < 100 && (l & (OMAP_DMA_CCR_RD_ACTIVE |
889 OMAP_DMA_CCR_WR_ACTIVE))) {
890 udelay(5);
891 i++;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800892 l = p->dma_read(CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700893 }
894 if (i >= 100)
Paul Walmsley7852ec02012-07-26 00:54:26 -0600895 pr_err("DMA drain did not complete on lch %d\n", lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700896 /* Restore OCP_SYSCONFIG */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800897 p->dma_write(sys_cf, OCP_SYSCONFIG, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700898 } else {
899 l &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800900 p->dma_write(l, CCR, lch);
Peter Ujfalusi0e4905c2010-10-11 14:18:56 -0700901 }
Santosh Shilimkar9da65a92009-10-22 14:46:31 -0700902
Russell King35453582012-04-14 18:57:10 +0100903 /*
904 * Ensure that data transferred by DMA is visible to any access
905 * after DMA has been disabled. This is important for coherent
906 * DMA regions.
907 */
908 mb();
909
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000910 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
911 int next_lch, cur_lch = lch;
Paul Walmsleybc4d8b52012-04-13 06:34:30 -0600912 char dma_chan_link_map[MAX_LOGICAL_DMA_CH_COUNT];
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000913
914 memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
915 do {
916 /* The loop case: we've been here already */
917 if (dma_chan_link_map[cur_lch])
918 break;
919 /* Mark the current channel */
920 dma_chan_link_map[cur_lch] = 1;
921
922 disable_lnk(cur_lch);
923
924 next_lch = dma_chan[cur_lch].next_lch;
925 cur_lch = next_lch;
926 } while (next_lch != -1);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000927 }
928
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000929 dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
930}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300931EXPORT_SYMBOL(omap_stop_dma);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000932
933/*
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300934 * Allows changing the DMA callback function or data. This may be needed if
935 * the driver shares a single DMA channel for multiple dma triggers.
936 */
937int omap_set_dma_callback(int lch,
Tony Lindgren97b7f712008-07-03 12:24:37 +0300938 void (*callback)(int lch, u16 ch_status, void *data),
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300939 void *data)
940{
941 unsigned long flags;
942
943 if (lch < 0)
944 return -ENODEV;
945
946 spin_lock_irqsave(&dma_chan_lock, flags);
947 if (dma_chan[lch].dev_id == -1) {
948 printk(KERN_ERR "DMA callback for not set for free channel\n");
949 spin_unlock_irqrestore(&dma_chan_lock, flags);
950 return -EINVAL;
951 }
952 dma_chan[lch].callback = callback;
953 dma_chan[lch].data = data;
954 spin_unlock_irqrestore(&dma_chan_lock, flags);
955
956 return 0;
957}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300958EXPORT_SYMBOL(omap_set_dma_callback);
Tony Lindgren709eb3e52006-09-25 12:45:45 +0300959
960/*
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000961 * Returns current physical source address for the given DMA channel.
962 * If the channel is running the caller must disable interrupts prior calling
963 * this function and process the returned value before re-enabling interrupt to
964 * prevent races with the interrupt handler. Note that in continuous mode there
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300965 * is a chance for CSSA_L register overflow between the two reads resulting
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000966 * in incorrect return value.
967 */
968dma_addr_t omap_get_dma_src_pos(int lch)
969{
Tony Lindgren0695de32007-05-07 18:24:14 -0700970 dma_addr_t offset = 0;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000971
Tony Lindgren82809602012-10-30 11:03:22 -0700972 if (dma_omap15xx())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800973 offset = p->dma_read(CPC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300974 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800975 offset = p->dma_read(CSAC, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000976
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -0800977 if (IS_DMA_ERRATA(DMA_ERRATA_3_3) && offset == 0)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800978 offset = p->dma_read(CSAC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +0300979
Tony Lindgren82809602012-10-30 11:03:22 -0700980 if (!dma_omap15xx()) {
Peter Ujfalusi7ba96682011-12-09 13:38:00 -0800981 /*
982 * CDAC == 0 indicates that the DMA transfer on the channel has
983 * not been started (no data has been transferred so far).
984 * Return the programmed source start address in this case.
985 */
986 if (likely(p->dma_read(CDAC, lch)))
987 offset = p->dma_read(CSAC, lch);
988 else
989 offset = p->dma_read(CSSA, lch);
990 }
991
Tony Lindgren82809602012-10-30 11:03:22 -0700992 if (dma_omap1())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800993 offset |= (p->dma_read(CSSA, lch) & 0xFFFF0000);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000994
995 return offset;
996}
Tony Lindgren97b7f712008-07-03 12:24:37 +0300997EXPORT_SYMBOL(omap_get_dma_src_pos);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000998
999/*
1000 * Returns current physical destination address for the given DMA channel.
1001 * If the channel is running the caller must disable interrupts prior calling
1002 * this function and process the returned value before re-enabling interrupt to
1003 * prevent races with the interrupt handler. Note that in continuous mode there
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001004 * is a chance for CDSA_L register overflow between the two reads resulting
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001005 * in incorrect return value.
1006 */
1007dma_addr_t omap_get_dma_dst_pos(int lch)
1008{
Tony Lindgren0695de32007-05-07 18:24:14 -07001009 dma_addr_t offset = 0;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001010
Tony Lindgren82809602012-10-30 11:03:22 -07001011 if (dma_omap15xx())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001012 offset = p->dma_read(CPC, lch);
Tony Lindgren0499bde2008-07-03 12:24:36 +03001013 else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001014 offset = p->dma_read(CDAC, lch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001015
Tony Lindgren0499bde2008-07-03 12:24:36 +03001016 /*
1017 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1018 * read before the DMA controller finished disabling the channel.
1019 */
Tony Lindgren82809602012-10-30 11:03:22 -07001020 if (!dma_omap15xx() && offset == 0) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001021 offset = p->dma_read(CDAC, lch);
Peter Ujfalusi06e80772011-12-09 13:38:00 -08001022 /*
1023 * CDAC == 0 indicates that the DMA transfer on the channel has
1024 * not been started (no data has been transferred so far).
1025 * Return the programmed destination start address in this case.
1026 */
1027 if (unlikely(!offset))
1028 offset = p->dma_read(CDSA, lch);
1029 }
Tony Lindgren0499bde2008-07-03 12:24:36 +03001030
Tony Lindgren82809602012-10-30 11:03:22 -07001031 if (dma_omap1())
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001032 offset |= (p->dma_read(CDSA, lch) & 0xFFFF0000);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001033
1034 return offset;
1035}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001036EXPORT_SYMBOL(omap_get_dma_dst_pos);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001037
Tony Lindgren0499bde2008-07-03 12:24:36 +03001038int omap_get_dma_active_status(int lch)
1039{
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001040 return (p->dma_read(CCR, lch) & OMAP_DMA_CCR_EN) != 0;
Tony Lindgren0499bde2008-07-03 12:24:36 +03001041}
1042EXPORT_SYMBOL(omap_get_dma_active_status);
1043
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001044int omap_dma_running(void)
1045{
1046 int lch;
1047
Tony Lindgren82809602012-10-30 11:03:22 -07001048 if (dma_omap1())
Janusz Krzysztofikf8e9e982009-12-11 16:16:33 -08001049 if (omap_lcd_dma_running())
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001050 return 1;
1051
1052 for (lch = 0; lch < dma_chan_count; lch++)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001053 if (p->dma_read(CCR, lch) & OMAP_DMA_CCR_EN)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001054 return 1;
1055
1056 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001057}
1058
1059/*
1060 * lch_queue DMA will start right after lch_head one is finished.
1061 * For this DMA link to start, you still need to start (see omap_start_dma)
1062 * the first one. That will fire up the entire queue.
1063 */
Tony Lindgren97b7f712008-07-03 12:24:37 +03001064void omap_dma_link_lch(int lch_head, int lch_queue)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001065{
1066 if (omap_dma_in_1510_mode()) {
Janusz Krzysztofik9f0f4ae2009-08-23 17:56:12 +02001067 if (lch_head == lch_queue) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001068 p->dma_write(p->dma_read(CCR, lch_head) | (3 << 8),
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001069 CCR, lch_head);
Janusz Krzysztofik9f0f4ae2009-08-23 17:56:12 +02001070 return;
1071 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001072 printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
1073 BUG();
1074 return;
1075 }
1076
1077 if ((dma_chan[lch_head].dev_id == -1) ||
1078 (dma_chan[lch_queue].dev_id == -1)) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001079 pr_err("omap_dma: trying to link non requested channels\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001080 dump_stack();
1081 }
1082
1083 dma_chan[lch_head].next_lch = lch_queue;
1084}
Tony Lindgren97b7f712008-07-03 12:24:37 +03001085EXPORT_SYMBOL(omap_dma_link_lch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001086
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001087/*----------------------------------------------------------------------------*/
1088
1089#ifdef CONFIG_ARCH_OMAP1
1090
1091static int omap1_dma_handle_ch(int ch)
1092{
Tony Lindgren0499bde2008-07-03 12:24:36 +03001093 u32 csr;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001094
1095 if (enable_1510_mode && ch >= 6) {
1096 csr = dma_chan[ch].saved_csr;
1097 dma_chan[ch].saved_csr = 0;
1098 } else
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001099 csr = p->dma_read(CSR, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001100 if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) {
1101 dma_chan[ch + 6].saved_csr = csr >> 7;
1102 csr &= 0x7f;
1103 }
1104 if ((csr & 0x3f) == 0)
1105 return 0;
1106 if (unlikely(dma_chan[ch].dev_id == -1)) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001107 pr_warn("Spurious interrupt from DMA channel %d (CSR %04x)\n",
1108 ch, csr);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001109 return 0;
1110 }
Tony Lindgren7ff879d2006-06-26 16:16:15 -07001111 if (unlikely(csr & OMAP1_DMA_TOUT_IRQ))
Paul Walmsley7852ec02012-07-26 00:54:26 -06001112 pr_warn("DMA timeout with device %d\n", dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001113 if (unlikely(csr & OMAP_DMA_DROP_IRQ))
Paul Walmsley7852ec02012-07-26 00:54:26 -06001114 pr_warn("DMA synchronization event drop occurred with device %d\n",
1115 dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001116 if (likely(csr & OMAP_DMA_BLOCK_IRQ))
1117 dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
1118 if (likely(dma_chan[ch].callback != NULL))
1119 dma_chan[ch].callback(ch, csr, dma_chan[ch].data);
Tony Lindgren97b7f712008-07-03 12:24:37 +03001120
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001121 return 1;
1122}
1123
Linus Torvalds0cd61b62006-10-06 10:53:39 -07001124static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001125{
1126 int ch = ((int) dev_id) - 1;
1127 int handled = 0;
1128
1129 for (;;) {
1130 int handled_now = 0;
1131
1132 handled_now += omap1_dma_handle_ch(ch);
1133 if (enable_1510_mode && dma_chan[ch + 6].saved_csr)
1134 handled_now += omap1_dma_handle_ch(ch + 6);
1135 if (!handled_now)
1136 break;
1137 handled += handled_now;
1138 }
1139
1140 return handled ? IRQ_HANDLED : IRQ_NONE;
1141}
1142
1143#else
1144#define omap1_dma_irq_handler NULL
1145#endif
1146
Tony Lindgren140455f2010-02-12 12:26:48 -08001147#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001148
1149static int omap2_dma_handle_ch(int ch)
1150{
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001151 u32 status = p->dma_read(CSR, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001152
Juha Yrjola31513692006-12-06 17:13:47 -08001153 if (!status) {
1154 if (printk_ratelimit())
Paul Walmsley7852ec02012-07-26 00:54:26 -06001155 pr_warn("Spurious DMA IRQ for lch %d\n", ch);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001156 p->dma_write(1 << ch, IRQSTATUS_L0, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001157 return 0;
Juha Yrjola31513692006-12-06 17:13:47 -08001158 }
1159 if (unlikely(dma_chan[ch].dev_id == -1)) {
1160 if (printk_ratelimit())
Paul Walmsley7852ec02012-07-26 00:54:26 -06001161 pr_warn("IRQ %04x for non-allocated DMA channel %d\n",
1162 status, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001163 return 0;
Juha Yrjola31513692006-12-06 17:13:47 -08001164 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001165 if (unlikely(status & OMAP_DMA_DROP_IRQ))
Paul Walmsley7852ec02012-07-26 00:54:26 -06001166 pr_info("DMA synchronization event drop occurred with device %d\n",
1167 dma_chan[ch].dev_id);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001168 if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ)) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001169 printk(KERN_INFO "DMA transaction error with device %d\n",
1170 dma_chan[ch].dev_id);
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001171 if (IS_DMA_ERRATA(DMA_ERRATA_i378)) {
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001172 u32 ccr;
1173
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001174 ccr = p->dma_read(CCR, ch);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001175 ccr &= ~OMAP_DMA_CCR_EN;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001176 p->dma_write(ccr, CCR, ch);
Santosh Shilimkara50f18c2008-12-10 17:36:53 -08001177 dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
1178 }
1179 }
Tony Lindgren7ff879d2006-06-26 16:16:15 -07001180 if (unlikely(status & OMAP2_DMA_SECURE_ERR_IRQ))
1181 printk(KERN_INFO "DMA secure error with device %d\n",
1182 dma_chan[ch].dev_id);
1183 if (unlikely(status & OMAP2_DMA_MISALIGNED_ERR_IRQ))
1184 printk(KERN_INFO "DMA misaligned error with device %d\n",
1185 dma_chan[ch].dev_id);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001186
Adrian Hunter4fb699b2010-11-24 13:23:21 +02001187 p->dma_write(status, CSR, ch);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001188 p->dma_write(1 << ch, IRQSTATUS_L0, ch);
Mathias Nymane860e6d2010-10-25 14:35:24 +00001189 /* read back the register to flush the write */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001190 p->dma_read(IRQSTATUS_L0, ch);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001191
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001192 /* If the ch is not chained then chain_id will be -1 */
1193 if (dma_chan[ch].chain_id != -1) {
1194 int chain_id = dma_chan[ch].chain_id;
1195 dma_chan[ch].state = DMA_CH_NOTSTARTED;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001196 if (p->dma_read(CLNK_CTRL, ch) & (1 << 15))
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001197 dma_chan[dma_chan[ch].next_linked_ch].state =
1198 DMA_CH_STARTED;
1199 if (dma_linked_lch[chain_id].chain_mode ==
1200 OMAP_DMA_DYNAMIC_CHAIN)
1201 disable_lnk(ch);
1202
1203 if (!OMAP_DMA_CHAIN_QEMPTY(chain_id))
1204 OMAP_DMA_CHAIN_INCQHEAD(chain_id);
1205
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001206 status = p->dma_read(CSR, ch);
Adrian Hunter4fb699b2010-11-24 13:23:21 +02001207 p->dma_write(status, CSR, ch);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001208 }
1209
Jarkko Nikula538528d2008-02-13 11:47:29 +02001210 if (likely(dma_chan[ch].callback != NULL))
1211 dma_chan[ch].callback(ch, status, dma_chan[ch].data);
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001212
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001213 return 0;
1214}
1215
1216/* STATUS register count is from 1-32 while our is 0-31 */
Linus Torvalds0cd61b62006-10-06 10:53:39 -07001217static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001218{
Santosh Shilimkar52176e72009-03-23 18:07:49 -07001219 u32 val, enable_reg;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001220 int i;
1221
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001222 val = p->dma_read(IRQSTATUS_L0, 0);
Juha Yrjola31513692006-12-06 17:13:47 -08001223 if (val == 0) {
1224 if (printk_ratelimit())
1225 printk(KERN_WARNING "Spurious DMA IRQ\n");
1226 return IRQ_HANDLED;
1227 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001228 enable_reg = p->dma_read(IRQENABLE_L0, 0);
Santosh Shilimkar52176e72009-03-23 18:07:49 -07001229 val &= enable_reg; /* Dispatch only relevant interrupts */
Tony Lindgren4d963722008-07-03 12:24:31 +03001230 for (i = 0; i < dma_lch_count && val != 0; i++) {
Juha Yrjola31513692006-12-06 17:13:47 -08001231 if (val & 1)
1232 omap2_dma_handle_ch(i);
1233 val >>= 1;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001234 }
1235
1236 return IRQ_HANDLED;
1237}
1238
1239static struct irqaction omap24xx_dma_irq = {
1240 .name = "DMA",
1241 .handler = omap2_dma_irq_handler,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001242};
1243
1244#else
1245static struct irqaction omap24xx_dma_irq;
1246#endif
1247
1248/*----------------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001249
Tony Lindgren9ce24822014-05-16 14:05:35 -07001250/*
1251 * Note that we are currently using only IRQENABLE_L0 and L1.
1252 * As the DSP may be using IRQENABLE_L2 and L3, let's not
1253 * touch those for now.
1254 */
Tero Kristof2d11852008-08-28 13:13:31 +00001255void omap_dma_global_context_save(void)
1256{
1257 omap_dma_global_context.dma_irqenable_l0 =
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001258 p->dma_read(IRQENABLE_L0, 0);
Tony Lindgren9ce24822014-05-16 14:05:35 -07001259 omap_dma_global_context.dma_irqenable_l1 =
1260 p->dma_read(IRQENABLE_L1, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00001261 omap_dma_global_context.dma_ocp_sysconfig =
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001262 p->dma_read(OCP_SYSCONFIG, 0);
1263 omap_dma_global_context.dma_gcr = p->dma_read(GCR, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00001264}
1265
1266void omap_dma_global_context_restore(void)
1267{
Aaro Koskinenbf07c9f2009-05-20 16:58:30 +03001268 int ch;
1269
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001270 p->dma_write(omap_dma_global_context.dma_gcr, GCR, 0);
1271 p->dma_write(omap_dma_global_context.dma_ocp_sysconfig,
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001272 OCP_SYSCONFIG, 0);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001273 p->dma_write(omap_dma_global_context.dma_irqenable_l0,
G, Manjunath Kondaiaha4c537c2010-12-20 18:27:17 -08001274 IRQENABLE_L0, 0);
Tony Lindgren9ce24822014-05-16 14:05:35 -07001275 p->dma_write(omap_dma_global_context.dma_irqenable_l1,
1276 IRQENABLE_L1, 0);
Tero Kristof2d11852008-08-28 13:13:31 +00001277
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001278 if (IS_DMA_ERRATA(DMA_ROMCODE_BUG))
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001279 p->dma_write(0x3 , IRQSTATUS_L0, 0);
Aaro Koskinenbf07c9f2009-05-20 16:58:30 +03001280
1281 for (ch = 0; ch < dma_chan_count; ch++)
1282 if (dma_chan[ch].dev_id != -1)
1283 omap_clear_dma(ch);
Tero Kristof2d11852008-08-28 13:13:31 +00001284}
1285
Russell King1b416c42013-11-02 13:00:03 +00001286struct omap_system_dma_plat_info *omap_get_plat_info(void)
1287{
1288 return p;
1289}
1290EXPORT_SYMBOL_GPL(omap_get_plat_info);
1291
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001292static int omap_system_dma_probe(struct platform_device *pdev)
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001293{
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001294 int ch, ret = 0;
1295 int dma_irq;
1296 char irq_name[4];
1297 int irq_rel;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001298
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001299 p = pdev->dev.platform_data;
1300 if (!p) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001301 dev_err(&pdev->dev,
1302 "%s: System DMA initialized without platform data\n",
1303 __func__);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001304 return -EINVAL;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001305 }
1306
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001307 d = p->dma_attr;
1308 errata = p->errata;
G, Manjunath Kondaiahd3c9be22010-12-20 18:27:18 -08001309
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001310 if ((d->dev_caps & RESERVE_CHANNEL) && omap_dma_reserve_channels
Chen Gange78f9602013-01-11 13:39:18 +08001311 && (omap_dma_reserve_channels < d->lch_count))
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001312 d->lch_count = omap_dma_reserve_channels;
Santosh Shilimkar2263f022009-03-23 18:07:48 -07001313
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001314 dma_lch_count = d->lch_count;
1315 dma_chan_count = dma_lch_count;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001316 enable_1510_mode = d->dev_caps & ENABLE_1510_MODE;
Tony Lindgren4d963722008-07-03 12:24:31 +03001317
Russell King9834f812013-11-08 18:10:42 +00001318 dma_chan = devm_kcalloc(&pdev->dev, dma_lch_count,
1319 sizeof(struct omap_dma_lch), GFP_KERNEL);
1320 if (!dma_chan) {
1321 dev_err(&pdev->dev, "%s: kzalloc fail\n", __func__);
1322 return -ENOMEM;
1323 }
1324
1325
Tony Lindgren82809602012-10-30 11:03:22 -07001326 if (dma_omap2plus()) {
Tony Lindgren4d963722008-07-03 12:24:31 +03001327 dma_linked_lch = kzalloc(sizeof(struct dma_link_info) *
1328 dma_lch_count, GFP_KERNEL);
1329 if (!dma_linked_lch) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001330 ret = -ENOMEM;
1331 goto exit_dma_lch_fail;
Tony Lindgren4d963722008-07-03 12:24:31 +03001332 }
1333 }
1334
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001335 spin_lock_init(&dma_chan_lock);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001336 for (ch = 0; ch < dma_chan_count; ch++) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001337 omap_clear_dma(ch);
Tony Lindgren82809602012-10-30 11:03:22 -07001338 if (dma_omap2plus())
Mika Westerbergada8d4a2010-05-14 12:05:25 -07001339 omap2_disable_irq_lch(ch);
1340
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001341 dma_chan[ch].dev_id = -1;
1342 dma_chan[ch].next_lch = -1;
1343
1344 if (ch >= 6 && enable_1510_mode)
1345 continue;
1346
Tony Lindgren82809602012-10-30 11:03:22 -07001347 if (dma_omap1()) {
Tony Lindgren97b7f712008-07-03 12:24:37 +03001348 /*
1349 * request_irq() doesn't like dev_id (ie. ch) being
1350 * zero, so we have to kludge around this.
1351 */
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001352 sprintf(&irq_name[0], "%d", ch);
1353 dma_irq = platform_get_irq_byname(pdev, irq_name);
1354
1355 if (dma_irq < 0) {
1356 ret = dma_irq;
1357 goto exit_dma_irq_fail;
1358 }
1359
1360 /* INT_DMA_LCD is handled in lcd_dma.c */
1361 if (dma_irq == INT_DMA_LCD)
1362 continue;
1363
1364 ret = request_irq(dma_irq,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001365 omap1_dma_irq_handler, 0, "DMA",
1366 (void *) (ch + 1));
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001367 if (ret != 0)
1368 goto exit_dma_irq_fail;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001369 }
1370 }
1371
Tony Lindgren82809602012-10-30 11:03:22 -07001372 if (d->dev_caps & IS_RW_PRIORITY)
Anand Gadiyarf8151e52007-12-01 12:14:11 -08001373 omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE,
1374 DMA_DEFAULT_FIFO_DEPTH, 0);
1375
Nishanth Menon76be4a52014-06-12 17:15:22 +05301376 if (dma_omap2plus() && !(d->dev_caps & DMA_ENGINE_HANDLE_IRQ)) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001377 strcpy(irq_name, "0");
1378 dma_irq = platform_get_irq_byname(pdev, irq_name);
1379 if (dma_irq < 0) {
1380 dev_err(&pdev->dev, "failed: request IRQ %d", dma_irq);
Wei Yongjun94b1d612013-07-16 20:10:46 +08001381 ret = dma_irq;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001382 goto exit_dma_lch_fail;
1383 }
1384 ret = setup_irq(dma_irq, &omap24xx_dma_irq);
1385 if (ret) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001386 dev_err(&pdev->dev, "set_up failed for IRQ %d for DMA (error %d)\n",
1387 dma_irq, ret);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001388 goto exit_dma_lch_fail;
Kalle Jokiniemiba50ea72009-03-26 15:59:00 +02001389 }
Kalle Jokiniemiaecedb92009-06-23 13:30:24 +03001390 }
1391
Tony Lindgren82809602012-10-30 11:03:22 -07001392 /* reserve dma channels 0 and 1 in high security devices on 34xx */
1393 if (d->dev_caps & HS_CHANNELS_RESERVED) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001394 pr_info("Reserving DMA channels 0 and 1 for HS ROM code\n");
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001395 dma_chan[0].dev_id = 0;
1396 dma_chan[1].dev_id = 1;
1397 }
1398 p->show_dma_caps();
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001399 return 0;
Tony Lindgren7e9bf842009-10-19 15:25:15 -07001400
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001401exit_dma_irq_fail:
Paul Walmsley7852ec02012-07-26 00:54:26 -06001402 dev_err(&pdev->dev, "unable to request IRQ %d for DMA (error %d)\n",
1403 dma_irq, ret);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001404 for (irq_rel = 0; irq_rel < ch; irq_rel++) {
1405 dma_irq = platform_get_irq(pdev, irq_rel);
1406 free_irq(dma_irq, (void *)(irq_rel + 1));
1407 }
1408
1409exit_dma_lch_fail:
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001410 return ret;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001411}
1412
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001413static int omap_system_dma_remove(struct platform_device *pdev)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001414{
1415 int dma_irq;
1416
Tony Lindgren82809602012-10-30 11:03:22 -07001417 if (dma_omap2plus()) {
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001418 char irq_name[4];
1419 strcpy(irq_name, "0");
1420 dma_irq = platform_get_irq_byname(pdev, irq_name);
Nishanth Menon76be4a52014-06-12 17:15:22 +05301421 if (dma_irq >= 0)
1422 remove_irq(dma_irq, &omap24xx_dma_irq);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001423 } else {
1424 int irq_rel = 0;
1425 for ( ; irq_rel < dma_chan_count; irq_rel++) {
1426 dma_irq = platform_get_irq(pdev, irq_rel);
1427 free_irq(dma_irq, (void *)(irq_rel + 1));
1428 }
1429 }
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001430 return 0;
1431}
1432
1433static struct platform_driver omap_system_dma_driver = {
1434 .probe = omap_system_dma_probe,
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001435 .remove = omap_system_dma_remove,
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -08001436 .driver = {
1437 .name = "omap_dma_system"
1438 },
1439};
1440
1441static int __init omap_system_dma_init(void)
1442{
1443 return platform_driver_register(&omap_system_dma_driver);
1444}
1445arch_initcall(omap_system_dma_init);
1446
1447static void __exit omap_system_dma_exit(void)
1448{
1449 platform_driver_unregister(&omap_system_dma_driver);
1450}
1451
1452MODULE_DESCRIPTION("OMAP SYSTEM DMA DRIVER");
1453MODULE_LICENSE("GPL");
1454MODULE_ALIAS("platform:" DRIVER_NAME);
1455MODULE_AUTHOR("Texas Instruments Inc");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001456
Santosh Shilimkar2263f022009-03-23 18:07:48 -07001457/*
1458 * Reserve the omap SDMA channels using cmdline bootarg
1459 * "omap_dma_reserve_ch=". The valid range is 1 to 32
1460 */
1461static int __init omap_dma_cmdline_reserve_ch(char *str)
1462{
1463 if (get_option(&str, &omap_dma_reserve_channels) != 1)
1464 omap_dma_reserve_channels = 0;
1465 return 1;
1466}
1467
1468__setup("omap_dma_reserve_ch=", omap_dma_cmdline_reserve_ch);
1469
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001470