Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/plat-omap/dma.c |
| 3 | * |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 4 | * Copyright (C) 2003 - 2008 Nokia Corporation |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 5 | * Author: Juha Yrjölä <juha.yrjola@nokia.com> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 6 | * 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 Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 9 | * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc. |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 10 | * Merged to support both OMAP1 and OMAP2 by Tony Lindgren <tony@atomide.com> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 11 | * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc. |
| 12 | * |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 13 | * Copyright (C) 2009 Texas Instruments |
| 14 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com> |
| 15 | * |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 16 | * Support functions for the OMAP internal DMA channels. |
| 17 | * |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 18 | * 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 Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 22 | * 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 Gleixner | 418ca1f0 | 2006-07-01 22:32:41 +0100 | [diff] [blame] | 34 | #include <linux/irq.h> |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 35 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Peter Ujfalusi | 0e4905c | 2010-10-11 14:18:56 -0700 | [diff] [blame] | 37 | #include <linux/delay.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 38 | |
Lokesh Vutla | 2b6c4e7 | 2012-10-15 14:04:53 -0700 | [diff] [blame] | 39 | #include <plat-omap/dma-omap.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 40 | |
Tony Lindgren | e4c060d | 2012-10-05 13:25:59 -0700 | [diff] [blame^] | 41 | #include "../mach-omap1/soc.h" |
| 42 | #include "../mach-omap2/soc.h" |
| 43 | |
Paul Walmsley | bc4d8b5 | 2012-04-13 06:34:30 -0600 | [diff] [blame] | 44 | /* |
| 45 | * MAX_LOGICAL_DMA_CH_COUNT: the maximum number of logical DMA |
| 46 | * channels that an instance of the SDMA IP block can support. Used |
| 47 | * to size arrays. (The actual maximum on a particular SoC may be less |
| 48 | * than this -- for example, OMAP1 SDMA instances only support 17 logical |
| 49 | * DMA channels.) |
| 50 | */ |
| 51 | #define MAX_LOGICAL_DMA_CH_COUNT 32 |
| 52 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 53 | #undef DEBUG |
| 54 | |
| 55 | #ifndef CONFIG_ARCH_OMAP1 |
| 56 | enum { DMA_CH_ALLOC_DONE, DMA_CH_PARAMS_SET_DONE, DMA_CH_STARTED, |
| 57 | DMA_CH_QUEUED, DMA_CH_NOTSTARTED, DMA_CH_PAUSED, DMA_CH_LINK_ENABLED |
| 58 | }; |
| 59 | |
| 60 | enum { DMA_CHAIN_STARTED, DMA_CHAIN_NOTSTARTED }; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 61 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 62 | |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 63 | #define OMAP_DMA_ACTIVE 0x01 |
Adrian Hunter | 4fb699b | 2010-11-24 13:23:21 +0200 | [diff] [blame] | 64 | #define OMAP2_DMA_CSR_CLEAR_MASK 0xffffffff |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 65 | |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 66 | #define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 67 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 68 | static struct omap_system_dma_plat_info *p; |
| 69 | static struct omap_dma_dev_attr *d; |
| 70 | |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 71 | static int enable_1510_mode; |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 72 | static u32 errata; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 73 | |
Tero Kristo | f2d1185 | 2008-08-28 13:13:31 +0000 | [diff] [blame] | 74 | static struct omap_dma_global_context_registers { |
| 75 | u32 dma_irqenable_l0; |
| 76 | u32 dma_ocp_sysconfig; |
| 77 | u32 dma_gcr; |
| 78 | } omap_dma_global_context; |
| 79 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 80 | struct 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 Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 93 | static struct dma_link_info *dma_linked_lch; |
| 94 | |
| 95 | #ifndef CONFIG_ARCH_OMAP1 |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 96 | |
| 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 Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 128 | |
| 129 | static int dma_lch_count; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 130 | static int dma_chan_count; |
Santosh Shilimkar | 2263f02 | 2009-03-23 18:07:48 -0700 | [diff] [blame] | 131 | static int omap_dma_reserve_channels; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 132 | |
| 133 | static spinlock_t dma_chan_lock; |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 134 | static struct omap_dma_lch *dma_chan; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 135 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 136 | static inline void disable_lnk(int lch); |
| 137 | static void omap_disable_channel_irq(int lch); |
| 138 | static inline void omap_enable_channel_irq(int lch); |
| 139 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 140 | #define REVISIT_24XX() printk(KERN_ERR "FIXME: no %s on 24xx\n", \ |
Harvey Harrison | 8e86f42 | 2008-03-04 15:08:02 -0800 | [diff] [blame] | 141 | __func__); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 142 | |
| 143 | #ifdef CONFIG_ARCH_OMAP15XX |
| 144 | /* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */ |
Aaro Koskinen | c776758 | 2011-01-27 16:39:43 -0800 | [diff] [blame] | 145 | static int omap_dma_in_1510_mode(void) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 146 | { |
| 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 Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 154 | static inline int get_gdma_dev(int req) |
| 155 | { |
| 156 | u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4; |
| 157 | int shift = ((req - 1) % 5) * 6; |
| 158 | |
| 159 | return ((omap_readl(reg) >> shift) & 0x3f) + 1; |
| 160 | } |
| 161 | |
| 162 | static inline void set_gdma_dev(int req, int dev) |
| 163 | { |
| 164 | u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4; |
| 165 | int shift = ((req - 1) % 5) * 6; |
| 166 | u32 l; |
| 167 | |
| 168 | l = omap_readl(reg); |
| 169 | l &= ~(0x3f << shift); |
| 170 | l |= (dev - 1) << shift; |
| 171 | omap_writel(l, reg); |
| 172 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 173 | #else |
| 174 | #define set_gdma_dev(req, dev) do {} while (0) |
Tony Lindgren | 2c799ce | 2012-02-24 10:34:35 -0800 | [diff] [blame] | 175 | #define omap_readl(reg) 0 |
| 176 | #define omap_writel(val, reg) do {} while (0) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 177 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 178 | |
Tony Lindgren | 54b693d | 2012-10-02 13:39:28 -0700 | [diff] [blame] | 179 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 709eb3e5 | 2006-09-25 12:45:45 +0300 | [diff] [blame] | 180 | void omap_set_dma_priority(int lch, int dst_port, int priority) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 181 | { |
| 182 | unsigned long reg; |
| 183 | u32 l; |
| 184 | |
Tony Lindgren | 709eb3e5 | 2006-09-25 12:45:45 +0300 | [diff] [blame] | 185 | if (cpu_class_is_omap1()) { |
| 186 | switch (dst_port) { |
| 187 | case OMAP_DMA_PORT_OCP_T1: /* FFFECC00 */ |
| 188 | reg = OMAP_TC_OCPT1_PRIOR; |
| 189 | break; |
| 190 | case OMAP_DMA_PORT_OCP_T2: /* FFFECCD0 */ |
| 191 | reg = OMAP_TC_OCPT2_PRIOR; |
| 192 | break; |
| 193 | case OMAP_DMA_PORT_EMIFF: /* FFFECC08 */ |
| 194 | reg = OMAP_TC_EMIFF_PRIOR; |
| 195 | break; |
| 196 | case OMAP_DMA_PORT_EMIFS: /* FFFECC04 */ |
| 197 | reg = OMAP_TC_EMIFS_PRIOR; |
| 198 | break; |
| 199 | default: |
| 200 | BUG(); |
| 201 | return; |
| 202 | } |
| 203 | l = omap_readl(reg); |
| 204 | l &= ~(0xf << 8); |
| 205 | l |= (priority & 0xf) << 8; |
| 206 | omap_writel(l, reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 207 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 208 | } |
Tony Lindgren | 54b693d | 2012-10-02 13:39:28 -0700 | [diff] [blame] | 209 | #endif |
| 210 | |
| 211 | #ifdef CONFIG_ARCH_OMAP2PLUS |
| 212 | void omap_set_dma_priority(int lch, int dst_port, int priority) |
| 213 | { |
| 214 | u32 ccr; |
| 215 | |
| 216 | ccr = p->dma_read(CCR, lch); |
| 217 | if (priority) |
| 218 | ccr |= (1 << 6); |
| 219 | else |
| 220 | ccr &= ~(1 << 6); |
| 221 | p->dma_write(ccr, CCR, lch); |
| 222 | } |
| 223 | #endif |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 224 | EXPORT_SYMBOL(omap_set_dma_priority); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 225 | |
| 226 | void omap_set_dma_transfer_params(int lch, int data_type, int elem_count, |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 227 | int frame_count, int sync_mode, |
| 228 | int dma_trigger, int src_or_dst_synch) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 229 | { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 230 | u32 l; |
| 231 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 232 | l = p->dma_read(CSDP, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 233 | l &= ~0x03; |
| 234 | l |= data_type; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 235 | p->dma_write(l, CSDP, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 236 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 237 | if (cpu_class_is_omap1()) { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 238 | u16 ccr; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 239 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 240 | ccr = p->dma_read(CCR, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 241 | ccr &= ~(1 << 5); |
| 242 | if (sync_mode == OMAP_DMA_SYNC_FRAME) |
| 243 | ccr |= 1 << 5; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 244 | p->dma_write(ccr, CCR, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 245 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 246 | ccr = p->dma_read(CCR2, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 247 | ccr &= ~(1 << 2); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 248 | if (sync_mode == OMAP_DMA_SYNC_BLOCK) |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 249 | ccr |= 1 << 2; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 250 | p->dma_write(ccr, CCR2, lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 251 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 252 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 253 | if (cpu_class_is_omap2() && dma_trigger) { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 254 | u32 val; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 255 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 256 | val = p->dma_read(CCR, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 257 | |
Anand Gadiyar | 4b3cf44 | 2009-01-15 13:09:53 +0200 | [diff] [blame] | 258 | /* DMA_SYNCHRO_CONTROL_UPPER depends on the channel number */ |
Samu Onkalo | 72a1179 | 2010-08-02 14:21:40 +0300 | [diff] [blame] | 259 | val &= ~((1 << 23) | (3 << 19) | 0x1f); |
Anand Gadiyar | 4b3cf44 | 2009-01-15 13:09:53 +0200 | [diff] [blame] | 260 | val |= (dma_trigger & ~0x1f) << 14; |
| 261 | val |= dma_trigger & 0x1f; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 262 | |
| 263 | if (sync_mode & OMAP_DMA_SYNC_FRAME) |
| 264 | val |= 1 << 5; |
Peter Ujfalusi | eca9e56 | 2006-06-26 16:16:06 -0700 | [diff] [blame] | 265 | else |
| 266 | val &= ~(1 << 5); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 267 | |
| 268 | if (sync_mode & OMAP_DMA_SYNC_BLOCK) |
| 269 | val |= 1 << 18; |
Peter Ujfalusi | eca9e56 | 2006-06-26 16:16:06 -0700 | [diff] [blame] | 270 | else |
| 271 | val &= ~(1 << 18); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 272 | |
Samu Onkalo | 72a1179 | 2010-08-02 14:21:40 +0300 | [diff] [blame] | 273 | if (src_or_dst_synch == OMAP_DMA_DST_SYNC_PREFETCH) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 274 | val &= ~(1 << 24); /* dest synch */ |
Samu Onkalo | 72a1179 | 2010-08-02 14:21:40 +0300 | [diff] [blame] | 275 | val |= (1 << 23); /* Prefetch */ |
| 276 | } else if (src_or_dst_synch) { |
| 277 | val |= 1 << 24; /* source synch */ |
| 278 | } else { |
| 279 | val &= ~(1 << 24); /* dest synch */ |
| 280 | } |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 281 | p->dma_write(val, CCR, lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 282 | } |
| 283 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 284 | p->dma_write(elem_count, CEN, lch); |
| 285 | p->dma_write(frame_count, CFN, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 286 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 287 | EXPORT_SYMBOL(omap_set_dma_transfer_params); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 288 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 289 | void omap_set_dma_color_mode(int lch, enum omap_dma_color_mode mode, u32 color) |
| 290 | { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 291 | BUG_ON(omap_dma_in_1510_mode()); |
| 292 | |
Tomi Valkeinen | 0815f8e | 2009-05-28 13:23:51 -0700 | [diff] [blame] | 293 | if (cpu_class_is_omap1()) { |
| 294 | u16 w; |
| 295 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 296 | w = p->dma_read(CCR2, lch); |
Tomi Valkeinen | 0815f8e | 2009-05-28 13:23:51 -0700 | [diff] [blame] | 297 | w &= ~0x03; |
| 298 | |
| 299 | switch (mode) { |
| 300 | case OMAP_DMA_CONSTANT_FILL: |
| 301 | w |= 0x01; |
| 302 | break; |
| 303 | case OMAP_DMA_TRANSPARENT_COPY: |
| 304 | w |= 0x02; |
| 305 | break; |
| 306 | case OMAP_DMA_COLOR_DIS: |
| 307 | break; |
| 308 | default: |
| 309 | BUG(); |
| 310 | } |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 311 | p->dma_write(w, CCR2, lch); |
Tomi Valkeinen | 0815f8e | 2009-05-28 13:23:51 -0700 | [diff] [blame] | 312 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 313 | w = p->dma_read(LCH_CTRL, lch); |
Tomi Valkeinen | 0815f8e | 2009-05-28 13:23:51 -0700 | [diff] [blame] | 314 | w &= ~0x0f; |
| 315 | /* Default is channel type 2D */ |
| 316 | if (mode) { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 317 | p->dma_write(color, COLOR, lch); |
Tomi Valkeinen | 0815f8e | 2009-05-28 13:23:51 -0700 | [diff] [blame] | 318 | w |= 1; /* Channel type G */ |
| 319 | } |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 320 | p->dma_write(w, LCH_CTRL, lch); |
Tomi Valkeinen | 0815f8e | 2009-05-28 13:23:51 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 323 | if (cpu_class_is_omap2()) { |
Tomi Valkeinen | 0815f8e | 2009-05-28 13:23:51 -0700 | [diff] [blame] | 324 | u32 val; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 325 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 326 | val = p->dma_read(CCR, lch); |
Tomi Valkeinen | 0815f8e | 2009-05-28 13:23:51 -0700 | [diff] [blame] | 327 | val &= ~((1 << 17) | (1 << 16)); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 328 | |
Tomi Valkeinen | 0815f8e | 2009-05-28 13:23:51 -0700 | [diff] [blame] | 329 | switch (mode) { |
| 330 | case OMAP_DMA_CONSTANT_FILL: |
| 331 | val |= 1 << 16; |
| 332 | break; |
| 333 | case OMAP_DMA_TRANSPARENT_COPY: |
| 334 | val |= 1 << 17; |
| 335 | break; |
| 336 | case OMAP_DMA_COLOR_DIS: |
| 337 | break; |
| 338 | default: |
| 339 | BUG(); |
| 340 | } |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 341 | p->dma_write(val, CCR, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 342 | |
Tomi Valkeinen | 0815f8e | 2009-05-28 13:23:51 -0700 | [diff] [blame] | 343 | color &= 0xffffff; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 344 | p->dma_write(color, COLOR, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 345 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 346 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 347 | EXPORT_SYMBOL(omap_set_dma_color_mode); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 348 | |
Tony Lindgren | 709eb3e5 | 2006-09-25 12:45:45 +0300 | [diff] [blame] | 349 | void omap_set_dma_write_mode(int lch, enum omap_dma_write_mode mode) |
| 350 | { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 351 | if (cpu_class_is_omap2()) { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 352 | u32 csdp; |
| 353 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 354 | csdp = p->dma_read(CSDP, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 355 | csdp &= ~(0x3 << 16); |
| 356 | csdp |= (mode << 16); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 357 | p->dma_write(csdp, CSDP, lch); |
Tony Lindgren | 709eb3e5 | 2006-09-25 12:45:45 +0300 | [diff] [blame] | 358 | } |
| 359 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 360 | EXPORT_SYMBOL(omap_set_dma_write_mode); |
Tony Lindgren | 709eb3e5 | 2006-09-25 12:45:45 +0300 | [diff] [blame] | 361 | |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 362 | void omap_set_dma_channel_mode(int lch, enum omap_dma_channel_mode mode) |
| 363 | { |
| 364 | if (cpu_class_is_omap1() && !cpu_is_omap15xx()) { |
| 365 | u32 l; |
| 366 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 367 | l = p->dma_read(LCH_CTRL, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 368 | l &= ~0x7; |
| 369 | l |= mode; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 370 | p->dma_write(l, LCH_CTRL, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | EXPORT_SYMBOL(omap_set_dma_channel_mode); |
| 374 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 375 | /* Note that src_port is only for omap1 */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 376 | void omap_set_dma_src_params(int lch, int src_port, int src_amode, |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 377 | unsigned long src_start, |
| 378 | int src_ei, int src_fi) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 379 | { |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 380 | u32 l; |
| 381 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 382 | if (cpu_class_is_omap1()) { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 383 | u16 w; |
| 384 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 385 | w = p->dma_read(CSDP, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 386 | w &= ~(0x1f << 2); |
| 387 | w |= src_port << 2; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 388 | p->dma_write(w, CSDP, lch); |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 389 | } |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 390 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 391 | l = p->dma_read(CCR, lch); |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 392 | l &= ~(0x03 << 12); |
| 393 | l |= src_amode << 12; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 394 | p->dma_write(l, CCR, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 395 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 396 | p->dma_write(src_start, CSSA, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 397 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 398 | p->dma_write(src_ei, CSEI, lch); |
| 399 | p->dma_write(src_fi, CSFI, lch); |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 400 | } |
| 401 | EXPORT_SYMBOL(omap_set_dma_src_params); |
| 402 | |
| 403 | void omap_set_dma_params(int lch, struct omap_dma_channel_params *params) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 404 | { |
| 405 | omap_set_dma_transfer_params(lch, params->data_type, |
| 406 | params->elem_count, params->frame_count, |
| 407 | params->sync_mode, params->trigger, |
| 408 | params->src_or_dst_synch); |
| 409 | omap_set_dma_src_params(lch, params->src_port, |
| 410 | params->src_amode, params->src_start, |
| 411 | params->src_ei, params->src_fi); |
| 412 | |
| 413 | omap_set_dma_dest_params(lch, params->dst_port, |
| 414 | params->dst_amode, params->dst_start, |
| 415 | params->dst_ei, params->dst_fi); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 416 | if (params->read_prio || params->write_prio) |
| 417 | omap_dma_set_prio_lch(lch, params->read_prio, |
| 418 | params->write_prio); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 419 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 420 | EXPORT_SYMBOL(omap_set_dma_params); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 421 | |
| 422 | void omap_set_dma_src_index(int lch, int eidx, int fidx) |
| 423 | { |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 424 | if (cpu_class_is_omap2()) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 425 | return; |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 426 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 427 | p->dma_write(eidx, CSEI, lch); |
| 428 | p->dma_write(fidx, CSFI, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 429 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 430 | EXPORT_SYMBOL(omap_set_dma_src_index); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 431 | |
| 432 | void omap_set_dma_src_data_pack(int lch, int enable) |
| 433 | { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 434 | u32 l; |
| 435 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 436 | l = p->dma_read(CSDP, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 437 | l &= ~(1 << 6); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 438 | if (enable) |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 439 | l |= (1 << 6); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 440 | p->dma_write(l, CSDP, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 441 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 442 | EXPORT_SYMBOL(omap_set_dma_src_data_pack); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 443 | |
| 444 | void omap_set_dma_src_burst_mode(int lch, enum omap_dma_burst_mode burst_mode) |
| 445 | { |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 446 | unsigned int burst = 0; |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 447 | u32 l; |
| 448 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 449 | l = p->dma_read(CSDP, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 450 | l &= ~(0x03 << 7); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 451 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 452 | switch (burst_mode) { |
| 453 | case OMAP_DMA_DATA_BURST_DIS: |
| 454 | break; |
| 455 | case OMAP_DMA_DATA_BURST_4: |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 456 | if (cpu_class_is_omap2()) |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 457 | burst = 0x1; |
| 458 | else |
| 459 | burst = 0x2; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 460 | break; |
| 461 | case OMAP_DMA_DATA_BURST_8: |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 462 | if (cpu_class_is_omap2()) { |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 463 | burst = 0x2; |
| 464 | break; |
| 465 | } |
manjugk manjugk | ea221a6 | 2010-05-14 12:05:25 -0700 | [diff] [blame] | 466 | /* |
| 467 | * not supported by current hardware on OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 468 | * w |= (0x03 << 7); |
| 469 | * fall through |
| 470 | */ |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 471 | case OMAP_DMA_DATA_BURST_16: |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 472 | if (cpu_class_is_omap2()) { |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 473 | burst = 0x3; |
| 474 | break; |
| 475 | } |
manjugk manjugk | ea221a6 | 2010-05-14 12:05:25 -0700 | [diff] [blame] | 476 | /* |
| 477 | * OMAP1 don't support burst 16 |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 478 | * fall through |
| 479 | */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 480 | default: |
| 481 | BUG(); |
| 482 | } |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 483 | |
| 484 | l |= (burst << 7); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 485 | p->dma_write(l, CSDP, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 486 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 487 | EXPORT_SYMBOL(omap_set_dma_src_burst_mode); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 488 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 489 | /* Note that dest_port is only for OMAP1 */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 490 | void omap_set_dma_dest_params(int lch, int dest_port, int dest_amode, |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 491 | unsigned long dest_start, |
| 492 | int dst_ei, int dst_fi) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 493 | { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 494 | u32 l; |
| 495 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 496 | if (cpu_class_is_omap1()) { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 497 | l = p->dma_read(CSDP, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 498 | l &= ~(0x1f << 9); |
| 499 | l |= dest_port << 9; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 500 | p->dma_write(l, CSDP, lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 501 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 502 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 503 | l = p->dma_read(CCR, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 504 | l &= ~(0x03 << 14); |
| 505 | l |= dest_amode << 14; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 506 | p->dma_write(l, CCR, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 507 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 508 | p->dma_write(dest_start, CDSA, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 509 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 510 | p->dma_write(dst_ei, CDEI, lch); |
| 511 | p->dma_write(dst_fi, CDFI, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 512 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 513 | EXPORT_SYMBOL(omap_set_dma_dest_params); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 514 | |
| 515 | void omap_set_dma_dest_index(int lch, int eidx, int fidx) |
| 516 | { |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 517 | if (cpu_class_is_omap2()) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 518 | return; |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 519 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 520 | p->dma_write(eidx, CDEI, lch); |
| 521 | p->dma_write(fidx, CDFI, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 522 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 523 | EXPORT_SYMBOL(omap_set_dma_dest_index); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 524 | |
| 525 | void omap_set_dma_dest_data_pack(int lch, int enable) |
| 526 | { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 527 | u32 l; |
| 528 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 529 | l = p->dma_read(CSDP, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 530 | l &= ~(1 << 13); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 531 | if (enable) |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 532 | l |= 1 << 13; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 533 | p->dma_write(l, CSDP, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 534 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 535 | EXPORT_SYMBOL(omap_set_dma_dest_data_pack); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 536 | |
| 537 | void omap_set_dma_dest_burst_mode(int lch, enum omap_dma_burst_mode burst_mode) |
| 538 | { |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 539 | unsigned int burst = 0; |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 540 | u32 l; |
| 541 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 542 | l = p->dma_read(CSDP, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 543 | l &= ~(0x03 << 14); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 544 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 545 | switch (burst_mode) { |
| 546 | case OMAP_DMA_DATA_BURST_DIS: |
| 547 | break; |
| 548 | case OMAP_DMA_DATA_BURST_4: |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 549 | if (cpu_class_is_omap2()) |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 550 | burst = 0x1; |
| 551 | else |
| 552 | burst = 0x2; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 553 | break; |
| 554 | case OMAP_DMA_DATA_BURST_8: |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 555 | if (cpu_class_is_omap2()) |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 556 | burst = 0x2; |
| 557 | else |
| 558 | burst = 0x3; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 559 | break; |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 560 | case OMAP_DMA_DATA_BURST_16: |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 561 | if (cpu_class_is_omap2()) { |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 562 | burst = 0x3; |
| 563 | break; |
| 564 | } |
manjugk manjugk | ea221a6 | 2010-05-14 12:05:25 -0700 | [diff] [blame] | 565 | /* |
| 566 | * OMAP1 don't support burst 16 |
Kyungmin Park | 6dc3c8f | 2006-06-26 16:16:14 -0700 | [diff] [blame] | 567 | * fall through |
| 568 | */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 569 | default: |
| 570 | printk(KERN_ERR "Invalid DMA burst mode\n"); |
| 571 | BUG(); |
| 572 | return; |
| 573 | } |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 574 | l |= (burst << 14); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 575 | p->dma_write(l, CSDP, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 576 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 577 | EXPORT_SYMBOL(omap_set_dma_dest_burst_mode); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 578 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 579 | static inline void omap_enable_channel_irq(int lch) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 580 | { |
Tony Lindgren | 7ff879d | 2006-06-26 16:16:15 -0700 | [diff] [blame] | 581 | /* Clear CSR */ |
| 582 | if (cpu_class_is_omap1()) |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 583 | p->dma_read(CSR, lch); |
| 584 | else |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 585 | p->dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 586 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 587 | /* Enable some nice interrupts. */ |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 588 | p->dma_write(dma_chan[lch].enabled_irqs, CICR, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 589 | } |
| 590 | |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 591 | static inline void omap_disable_channel_irq(int lch) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 592 | { |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 593 | /* disable channel interrupts */ |
| 594 | p->dma_write(0, CICR, lch); |
| 595 | /* Clear CSR */ |
| 596 | if (cpu_class_is_omap1()) |
| 597 | p->dma_read(CSR, lch); |
| 598 | else |
| 599 | p->dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | void omap_enable_dma_irq(int lch, u16 bits) |
| 603 | { |
| 604 | dma_chan[lch].enabled_irqs |= bits; |
| 605 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 606 | EXPORT_SYMBOL(omap_enable_dma_irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 607 | |
| 608 | void omap_disable_dma_irq(int lch, u16 bits) |
| 609 | { |
| 610 | dma_chan[lch].enabled_irqs &= ~bits; |
| 611 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 612 | EXPORT_SYMBOL(omap_disable_dma_irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 613 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 614 | static inline void enable_lnk(int lch) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 615 | { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 616 | u32 l; |
| 617 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 618 | l = p->dma_read(CLNK_CTRL, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 619 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 620 | if (cpu_class_is_omap1()) |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 621 | l &= ~(1 << 14); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 622 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 623 | /* Set the ENABLE_LNK bits */ |
| 624 | if (dma_chan[lch].next_lch != -1) |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 625 | l = dma_chan[lch].next_lch | (1 << 15); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 626 | |
| 627 | #ifndef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 628 | if (cpu_class_is_omap2()) |
| 629 | if (dma_chan[lch].next_linked_ch != -1) |
| 630 | l = dma_chan[lch].next_linked_ch | (1 << 15); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 631 | #endif |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 632 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 633 | p->dma_write(l, CLNK_CTRL, lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 634 | } |
| 635 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 636 | static inline void disable_lnk(int lch) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 637 | { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 638 | u32 l; |
| 639 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 640 | l = p->dma_read(CLNK_CTRL, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 641 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 642 | /* Disable interrupts */ |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 643 | omap_disable_channel_irq(lch); |
| 644 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 645 | if (cpu_class_is_omap1()) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 646 | /* Set the STOP_LNK bit */ |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 647 | l |= 1 << 14; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 648 | } |
| 649 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 650 | if (cpu_class_is_omap2()) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 651 | /* Clear the ENABLE_LNK bit */ |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 652 | l &= ~(1 << 15); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 653 | } |
| 654 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 655 | p->dma_write(l, CLNK_CTRL, lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 656 | dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE; |
| 657 | } |
| 658 | |
| 659 | static inline void omap2_enable_irq_lch(int lch) |
| 660 | { |
| 661 | u32 val; |
Tao Hu | ee90732 | 2009-11-10 18:55:17 -0800 | [diff] [blame] | 662 | unsigned long flags; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 663 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 664 | if (!cpu_class_is_omap2()) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 665 | return; |
| 666 | |
Tao Hu | ee90732 | 2009-11-10 18:55:17 -0800 | [diff] [blame] | 667 | spin_lock_irqsave(&dma_chan_lock, flags); |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 668 | /* clear IRQ STATUS */ |
| 669 | p->dma_write(1 << lch, IRQSTATUS_L0, lch); |
| 670 | /* Enable interrupt */ |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 671 | val = p->dma_read(IRQENABLE_L0, lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 672 | val |= 1 << lch; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 673 | p->dma_write(val, IRQENABLE_L0, lch); |
Tao Hu | ee90732 | 2009-11-10 18:55:17 -0800 | [diff] [blame] | 674 | spin_unlock_irqrestore(&dma_chan_lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 675 | } |
| 676 | |
Mika Westerberg | ada8d4a | 2010-05-14 12:05:25 -0700 | [diff] [blame] | 677 | static inline void omap2_disable_irq_lch(int lch) |
| 678 | { |
| 679 | u32 val; |
| 680 | unsigned long flags; |
| 681 | |
| 682 | if (!cpu_class_is_omap2()) |
| 683 | return; |
| 684 | |
| 685 | spin_lock_irqsave(&dma_chan_lock, flags); |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 686 | /* Disable interrupt */ |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 687 | val = p->dma_read(IRQENABLE_L0, lch); |
Mika Westerberg | ada8d4a | 2010-05-14 12:05:25 -0700 | [diff] [blame] | 688 | val &= ~(1 << lch); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 689 | p->dma_write(val, IRQENABLE_L0, lch); |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 690 | /* clear IRQ STATUS */ |
| 691 | p->dma_write(1 << lch, IRQSTATUS_L0, lch); |
Mika Westerberg | ada8d4a | 2010-05-14 12:05:25 -0700 | [diff] [blame] | 692 | spin_unlock_irqrestore(&dma_chan_lock, flags); |
| 693 | } |
| 694 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 695 | int omap_request_dma(int dev_id, const char *dev_name, |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 696 | void (*callback)(int lch, u16 ch_status, void *data), |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 697 | void *data, int *dma_ch_out) |
| 698 | { |
| 699 | int ch, free_ch = -1; |
| 700 | unsigned long flags; |
| 701 | struct omap_dma_lch *chan; |
| 702 | |
| 703 | spin_lock_irqsave(&dma_chan_lock, flags); |
| 704 | for (ch = 0; ch < dma_chan_count; ch++) { |
| 705 | if (free_ch == -1 && dma_chan[ch].dev_id == -1) { |
| 706 | free_ch = ch; |
| 707 | if (dev_id == 0) |
| 708 | break; |
| 709 | } |
| 710 | } |
| 711 | if (free_ch == -1) { |
| 712 | spin_unlock_irqrestore(&dma_chan_lock, flags); |
| 713 | return -EBUSY; |
| 714 | } |
| 715 | chan = dma_chan + free_ch; |
| 716 | chan->dev_id = dev_id; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 717 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 718 | if (p->clear_lch_regs) |
| 719 | p->clear_lch_regs(free_ch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 720 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 721 | if (cpu_class_is_omap2()) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 722 | omap_clear_dma(free_ch); |
| 723 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 724 | spin_unlock_irqrestore(&dma_chan_lock, flags); |
| 725 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 726 | chan->dev_name = dev_name; |
| 727 | chan->callback = callback; |
| 728 | chan->data = data; |
Jarkko Nikula | a92fda1 | 2009-01-29 08:57:12 -0800 | [diff] [blame] | 729 | chan->flags = 0; |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 730 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 731 | #ifndef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 732 | if (cpu_class_is_omap2()) { |
| 733 | chan->chain_id = -1; |
| 734 | chan->next_linked_ch = -1; |
| 735 | } |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 736 | #endif |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 737 | |
Tony Lindgren | 7ff879d | 2006-06-26 16:16:15 -0700 | [diff] [blame] | 738 | chan->enabled_irqs = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 739 | |
Tony Lindgren | 7ff879d | 2006-06-26 16:16:15 -0700 | [diff] [blame] | 740 | if (cpu_class_is_omap1()) |
| 741 | chan->enabled_irqs |= OMAP1_DMA_TOUT_IRQ; |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 742 | else if (cpu_class_is_omap2()) |
Tony Lindgren | 7ff879d | 2006-06-26 16:16:15 -0700 | [diff] [blame] | 743 | chan->enabled_irqs |= OMAP2_DMA_MISALIGNED_ERR_IRQ | |
| 744 | OMAP2_DMA_TRANS_ERR_IRQ; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 745 | |
| 746 | if (cpu_is_omap16xx()) { |
| 747 | /* If the sync device is set, configure it dynamically. */ |
| 748 | if (dev_id != 0) { |
| 749 | set_gdma_dev(free_ch + 1, dev_id); |
| 750 | dev_id = free_ch + 1; |
| 751 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 752 | /* |
| 753 | * Disable the 1510 compatibility mode and set the sync device |
| 754 | * id. |
| 755 | */ |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 756 | p->dma_write(dev_id | (1 << 10), CCR, free_ch); |
Zebediah C. McClure | 557096f | 2009-03-23 18:07:44 -0700 | [diff] [blame] | 757 | } else if (cpu_is_omap7xx() || cpu_is_omap15xx()) { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 758 | p->dma_write(dev_id, CCR, free_ch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 759 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 760 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 761 | if (cpu_class_is_omap2()) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 762 | omap_enable_channel_irq(free_ch); |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 763 | omap2_enable_irq_lch(free_ch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 766 | *dma_ch_out = free_ch; |
| 767 | |
| 768 | return 0; |
| 769 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 770 | EXPORT_SYMBOL(omap_request_dma); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 771 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 772 | void omap_free_dma(int lch) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 773 | { |
| 774 | unsigned long flags; |
| 775 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 776 | if (dma_chan[lch].dev_id == -1) { |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 777 | pr_err("omap_dma: trying to free unallocated DMA channel %d\n", |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 778 | lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 779 | return; |
| 780 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 781 | |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 782 | /* Disable interrupt for logical channel */ |
| 783 | if (cpu_class_is_omap2()) |
Mika Westerberg | ada8d4a | 2010-05-14 12:05:25 -0700 | [diff] [blame] | 784 | omap2_disable_irq_lch(lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 785 | |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 786 | /* Disable all DMA interrupts for the channel. */ |
| 787 | omap_disable_channel_irq(lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 788 | |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 789 | /* Make sure the DMA transfer is stopped. */ |
| 790 | p->dma_write(0, CCR, lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 791 | |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 792 | /* Clear registers */ |
| 793 | if (cpu_class_is_omap2()) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 794 | omap_clear_dma(lch); |
Santosh Shilimkar | da1b94e | 2009-04-23 11:10:40 -0700 | [diff] [blame] | 795 | |
| 796 | spin_lock_irqsave(&dma_chan_lock, flags); |
| 797 | dma_chan[lch].dev_id = -1; |
| 798 | dma_chan[lch].next_lch = -1; |
| 799 | dma_chan[lch].callback = NULL; |
| 800 | spin_unlock_irqrestore(&dma_chan_lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 801 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 802 | EXPORT_SYMBOL(omap_free_dma); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 803 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 804 | /** |
| 805 | * @brief omap_dma_set_global_params : Set global priority settings for dma |
| 806 | * |
| 807 | * @param arb_rate |
| 808 | * @param max_fifo_depth |
Anuj Aggarwal | 70cf644 | 2009-10-14 09:56:34 -0700 | [diff] [blame] | 809 | * @param tparams - Number of threads to reserve : DMA_THREAD_RESERVE_NORM |
| 810 | * DMA_THREAD_RESERVE_ONET |
| 811 | * DMA_THREAD_RESERVE_TWOT |
| 812 | * DMA_THREAD_RESERVE_THREET |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 813 | */ |
| 814 | void |
| 815 | omap_dma_set_global_params(int arb_rate, int max_fifo_depth, int tparams) |
| 816 | { |
| 817 | u32 reg; |
| 818 | |
| 819 | if (!cpu_class_is_omap2()) { |
Harvey Harrison | 8e86f42 | 2008-03-04 15:08:02 -0800 | [diff] [blame] | 820 | printk(KERN_ERR "FIXME: no %s on 15xx/16xx\n", __func__); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 821 | return; |
| 822 | } |
| 823 | |
Anuj Aggarwal | 70cf644 | 2009-10-14 09:56:34 -0700 | [diff] [blame] | 824 | if (max_fifo_depth == 0) |
| 825 | max_fifo_depth = 1; |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 826 | if (arb_rate == 0) |
| 827 | arb_rate = 1; |
| 828 | |
Anuj Aggarwal | 70cf644 | 2009-10-14 09:56:34 -0700 | [diff] [blame] | 829 | reg = 0xff & max_fifo_depth; |
| 830 | reg |= (0x3 & tparams) << 12; |
| 831 | reg |= (arb_rate & 0xff) << 16; |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 832 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 833 | p->dma_write(reg, GCR, 0); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 834 | } |
| 835 | EXPORT_SYMBOL(omap_dma_set_global_params); |
| 836 | |
| 837 | /** |
| 838 | * @brief omap_dma_set_prio_lch : Set channel wise priority settings |
| 839 | * |
| 840 | * @param lch |
| 841 | * @param read_prio - Read priority |
| 842 | * @param write_prio - Write priority |
| 843 | * Both of the above can be set with one of the following values : |
| 844 | * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW |
| 845 | */ |
| 846 | int |
| 847 | omap_dma_set_prio_lch(int lch, unsigned char read_prio, |
| 848 | unsigned char write_prio) |
| 849 | { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 850 | u32 l; |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 851 | |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 852 | if (unlikely((lch < 0 || lch >= dma_lch_count))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 853 | printk(KERN_ERR "Invalid channel id\n"); |
| 854 | return -EINVAL; |
| 855 | } |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 856 | l = p->dma_read(CCR, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 857 | l &= ~((1 << 6) | (1 << 26)); |
Santosh Shilimkar | d07c3df | 2012-04-28 20:19:10 +0530 | [diff] [blame] | 858 | if (cpu_class_is_omap2() && !cpu_is_omap242x()) |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 859 | l |= ((read_prio & 0x1) << 6) | ((write_prio & 0x1) << 26); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 860 | else |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 861 | l |= ((read_prio & 0x1) << 6); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 862 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 863 | p->dma_write(l, CCR, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 864 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 865 | return 0; |
| 866 | } |
| 867 | EXPORT_SYMBOL(omap_dma_set_prio_lch); |
| 868 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 869 | /* |
| 870 | * Clears any DMA state so the DMA engine is ready to restart with new buffers |
| 871 | * through omap_start_dma(). Any buffers in flight are discarded. |
| 872 | */ |
| 873 | void omap_clear_dma(int lch) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 874 | { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 875 | unsigned long flags; |
| 876 | |
| 877 | local_irq_save(flags); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 878 | p->clear_dma(lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 879 | local_irq_restore(flags); |
| 880 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 881 | EXPORT_SYMBOL(omap_clear_dma); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 882 | |
| 883 | void omap_start_dma(int lch) |
| 884 | { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 885 | u32 l; |
| 886 | |
manjugk manjugk | 519e616 | 2010-03-04 07:11:56 +0000 | [diff] [blame] | 887 | /* |
| 888 | * The CPC/CDAC register needs to be initialized to zero |
| 889 | * before starting dma transfer. |
| 890 | */ |
| 891 | if (cpu_is_omap15xx()) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 892 | p->dma_write(0, CPC, lch); |
manjugk manjugk | 519e616 | 2010-03-04 07:11:56 +0000 | [diff] [blame] | 893 | else |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 894 | p->dma_write(0, CDAC, lch); |
manjugk manjugk | 519e616 | 2010-03-04 07:11:56 +0000 | [diff] [blame] | 895 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 896 | if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) { |
| 897 | int next_lch, cur_lch; |
Paul Walmsley | bc4d8b5 | 2012-04-13 06:34:30 -0600 | [diff] [blame] | 898 | char dma_chan_link_map[MAX_LOGICAL_DMA_CH_COUNT]; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 899 | |
| 900 | dma_chan_link_map[lch] = 1; |
| 901 | /* Set the link register of the first channel */ |
| 902 | enable_lnk(lch); |
| 903 | |
| 904 | memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map)); |
| 905 | cur_lch = dma_chan[lch].next_lch; |
| 906 | do { |
| 907 | next_lch = dma_chan[cur_lch].next_lch; |
| 908 | |
| 909 | /* The loop case: we've been here already */ |
| 910 | if (dma_chan_link_map[cur_lch]) |
| 911 | break; |
| 912 | /* Mark the current channel */ |
| 913 | dma_chan_link_map[cur_lch] = 1; |
| 914 | |
| 915 | enable_lnk(cur_lch); |
| 916 | omap_enable_channel_irq(cur_lch); |
| 917 | |
| 918 | cur_lch = next_lch; |
| 919 | } while (next_lch != -1); |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 920 | } else if (IS_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS)) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 921 | p->dma_write(lch, CLNK_CTRL, lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 922 | |
| 923 | omap_enable_channel_irq(lch); |
| 924 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 925 | l = p->dma_read(CCR, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 926 | |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 927 | if (IS_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING)) |
| 928 | l |= OMAP_DMA_CCR_BUFFERING_DISABLE; |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 929 | l |= OMAP_DMA_CCR_EN; |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 930 | |
Russell King | 3545358 | 2012-04-14 18:57:10 +0100 | [diff] [blame] | 931 | /* |
| 932 | * As dma_write() uses IO accessors which are weakly ordered, there |
| 933 | * is no guarantee that data in coherent DMA memory will be visible |
| 934 | * to the DMA device. Add a memory barrier here to ensure that any |
| 935 | * such data is visible prior to enabling DMA. |
| 936 | */ |
| 937 | mb(); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 938 | p->dma_write(l, CCR, lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 939 | |
| 940 | dma_chan[lch].flags |= OMAP_DMA_ACTIVE; |
| 941 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 942 | EXPORT_SYMBOL(omap_start_dma); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 943 | |
| 944 | void omap_stop_dma(int lch) |
| 945 | { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 946 | u32 l; |
| 947 | |
Santosh Shilimkar | 9da65a9 | 2009-10-22 14:46:31 -0700 | [diff] [blame] | 948 | /* Disable all interrupts on the channel */ |
Oleg Matcovschi | bedfb7a | 2012-05-15 14:35:08 -0700 | [diff] [blame] | 949 | omap_disable_channel_irq(lch); |
Santosh Shilimkar | 9da65a9 | 2009-10-22 14:46:31 -0700 | [diff] [blame] | 950 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 951 | l = p->dma_read(CCR, lch); |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 952 | if (IS_DMA_ERRATA(DMA_ERRATA_i541) && |
| 953 | (l & OMAP_DMA_CCR_SEL_SRC_DST_SYNC)) { |
Peter Ujfalusi | 0e4905c | 2010-10-11 14:18:56 -0700 | [diff] [blame] | 954 | int i = 0; |
| 955 | u32 sys_cf; |
| 956 | |
| 957 | /* Configure No-Standby */ |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 958 | l = p->dma_read(OCP_SYSCONFIG, lch); |
Peter Ujfalusi | 0e4905c | 2010-10-11 14:18:56 -0700 | [diff] [blame] | 959 | sys_cf = l; |
| 960 | l &= ~DMA_SYSCONFIG_MIDLEMODE_MASK; |
| 961 | l |= DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_NO_IDLE); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 962 | p->dma_write(l , OCP_SYSCONFIG, 0); |
Peter Ujfalusi | 0e4905c | 2010-10-11 14:18:56 -0700 | [diff] [blame] | 963 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 964 | l = p->dma_read(CCR, lch); |
Peter Ujfalusi | 0e4905c | 2010-10-11 14:18:56 -0700 | [diff] [blame] | 965 | l &= ~OMAP_DMA_CCR_EN; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 966 | p->dma_write(l, CCR, lch); |
Peter Ujfalusi | 0e4905c | 2010-10-11 14:18:56 -0700 | [diff] [blame] | 967 | |
| 968 | /* Wait for sDMA FIFO drain */ |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 969 | l = p->dma_read(CCR, lch); |
Peter Ujfalusi | 0e4905c | 2010-10-11 14:18:56 -0700 | [diff] [blame] | 970 | while (i < 100 && (l & (OMAP_DMA_CCR_RD_ACTIVE | |
| 971 | OMAP_DMA_CCR_WR_ACTIVE))) { |
| 972 | udelay(5); |
| 973 | i++; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 974 | l = p->dma_read(CCR, lch); |
Peter Ujfalusi | 0e4905c | 2010-10-11 14:18:56 -0700 | [diff] [blame] | 975 | } |
| 976 | if (i >= 100) |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 977 | pr_err("DMA drain did not complete on lch %d\n", lch); |
Peter Ujfalusi | 0e4905c | 2010-10-11 14:18:56 -0700 | [diff] [blame] | 978 | /* Restore OCP_SYSCONFIG */ |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 979 | p->dma_write(sys_cf, OCP_SYSCONFIG, lch); |
Peter Ujfalusi | 0e4905c | 2010-10-11 14:18:56 -0700 | [diff] [blame] | 980 | } else { |
| 981 | l &= ~OMAP_DMA_CCR_EN; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 982 | p->dma_write(l, CCR, lch); |
Peter Ujfalusi | 0e4905c | 2010-10-11 14:18:56 -0700 | [diff] [blame] | 983 | } |
Santosh Shilimkar | 9da65a9 | 2009-10-22 14:46:31 -0700 | [diff] [blame] | 984 | |
Russell King | 3545358 | 2012-04-14 18:57:10 +0100 | [diff] [blame] | 985 | /* |
| 986 | * Ensure that data transferred by DMA is visible to any access |
| 987 | * after DMA has been disabled. This is important for coherent |
| 988 | * DMA regions. |
| 989 | */ |
| 990 | mb(); |
| 991 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 992 | if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) { |
| 993 | int next_lch, cur_lch = lch; |
Paul Walmsley | bc4d8b5 | 2012-04-13 06:34:30 -0600 | [diff] [blame] | 994 | char dma_chan_link_map[MAX_LOGICAL_DMA_CH_COUNT]; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 995 | |
| 996 | memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map)); |
| 997 | do { |
| 998 | /* The loop case: we've been here already */ |
| 999 | if (dma_chan_link_map[cur_lch]) |
| 1000 | break; |
| 1001 | /* Mark the current channel */ |
| 1002 | dma_chan_link_map[cur_lch] = 1; |
| 1003 | |
| 1004 | disable_lnk(cur_lch); |
| 1005 | |
| 1006 | next_lch = dma_chan[cur_lch].next_lch; |
| 1007 | cur_lch = next_lch; |
| 1008 | } while (next_lch != -1); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1011 | dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE; |
| 1012 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1013 | EXPORT_SYMBOL(omap_stop_dma); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1014 | |
| 1015 | /* |
Tony Lindgren | 709eb3e5 | 2006-09-25 12:45:45 +0300 | [diff] [blame] | 1016 | * Allows changing the DMA callback function or data. This may be needed if |
| 1017 | * the driver shares a single DMA channel for multiple dma triggers. |
| 1018 | */ |
| 1019 | int omap_set_dma_callback(int lch, |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1020 | void (*callback)(int lch, u16 ch_status, void *data), |
Tony Lindgren | 709eb3e5 | 2006-09-25 12:45:45 +0300 | [diff] [blame] | 1021 | void *data) |
| 1022 | { |
| 1023 | unsigned long flags; |
| 1024 | |
| 1025 | if (lch < 0) |
| 1026 | return -ENODEV; |
| 1027 | |
| 1028 | spin_lock_irqsave(&dma_chan_lock, flags); |
| 1029 | if (dma_chan[lch].dev_id == -1) { |
| 1030 | printk(KERN_ERR "DMA callback for not set for free channel\n"); |
| 1031 | spin_unlock_irqrestore(&dma_chan_lock, flags); |
| 1032 | return -EINVAL; |
| 1033 | } |
| 1034 | dma_chan[lch].callback = callback; |
| 1035 | dma_chan[lch].data = data; |
| 1036 | spin_unlock_irqrestore(&dma_chan_lock, flags); |
| 1037 | |
| 1038 | return 0; |
| 1039 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1040 | EXPORT_SYMBOL(omap_set_dma_callback); |
Tony Lindgren | 709eb3e5 | 2006-09-25 12:45:45 +0300 | [diff] [blame] | 1041 | |
| 1042 | /* |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1043 | * Returns current physical source address for the given DMA channel. |
| 1044 | * If the channel is running the caller must disable interrupts prior calling |
| 1045 | * this function and process the returned value before re-enabling interrupt to |
| 1046 | * prevent races with the interrupt handler. Note that in continuous mode there |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1047 | * is a chance for CSSA_L register overflow between the two reads resulting |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1048 | * in incorrect return value. |
| 1049 | */ |
| 1050 | dma_addr_t omap_get_dma_src_pos(int lch) |
| 1051 | { |
Tony Lindgren | 0695de3 | 2007-05-07 18:24:14 -0700 | [diff] [blame] | 1052 | dma_addr_t offset = 0; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1053 | |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1054 | if (cpu_is_omap15xx()) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1055 | offset = p->dma_read(CPC, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1056 | else |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1057 | offset = p->dma_read(CSAC, lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1058 | |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 1059 | if (IS_DMA_ERRATA(DMA_ERRATA_3_3) && offset == 0) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1060 | offset = p->dma_read(CSAC, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1061 | |
Peter Ujfalusi | 7ba9668 | 2011-12-09 13:38:00 -0800 | [diff] [blame] | 1062 | if (!cpu_is_omap15xx()) { |
| 1063 | /* |
| 1064 | * CDAC == 0 indicates that the DMA transfer on the channel has |
| 1065 | * not been started (no data has been transferred so far). |
| 1066 | * Return the programmed source start address in this case. |
| 1067 | */ |
| 1068 | if (likely(p->dma_read(CDAC, lch))) |
| 1069 | offset = p->dma_read(CSAC, lch); |
| 1070 | else |
| 1071 | offset = p->dma_read(CSSA, lch); |
| 1072 | } |
| 1073 | |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1074 | if (cpu_class_is_omap1()) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1075 | offset |= (p->dma_read(CSSA, lch) & 0xFFFF0000); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1076 | |
| 1077 | return offset; |
| 1078 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1079 | EXPORT_SYMBOL(omap_get_dma_src_pos); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1080 | |
| 1081 | /* |
| 1082 | * Returns current physical destination address for the given DMA channel. |
| 1083 | * If the channel is running the caller must disable interrupts prior calling |
| 1084 | * this function and process the returned value before re-enabling interrupt to |
| 1085 | * prevent races with the interrupt handler. Note that in continuous mode there |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1086 | * is a chance for CDSA_L register overflow between the two reads resulting |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1087 | * in incorrect return value. |
| 1088 | */ |
| 1089 | dma_addr_t omap_get_dma_dst_pos(int lch) |
| 1090 | { |
Tony Lindgren | 0695de3 | 2007-05-07 18:24:14 -0700 | [diff] [blame] | 1091 | dma_addr_t offset = 0; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1092 | |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1093 | if (cpu_is_omap15xx()) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1094 | offset = p->dma_read(CPC, lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1095 | else |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1096 | offset = p->dma_read(CDAC, lch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1097 | |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1098 | /* |
| 1099 | * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is |
| 1100 | * read before the DMA controller finished disabling the channel. |
| 1101 | */ |
Peter Ujfalusi | 06e8077 | 2011-12-09 13:38:00 -0800 | [diff] [blame] | 1102 | if (!cpu_is_omap15xx() && offset == 0) { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1103 | offset = p->dma_read(CDAC, lch); |
Peter Ujfalusi | 06e8077 | 2011-12-09 13:38:00 -0800 | [diff] [blame] | 1104 | /* |
| 1105 | * CDAC == 0 indicates that the DMA transfer on the channel has |
| 1106 | * not been started (no data has been transferred so far). |
| 1107 | * Return the programmed destination start address in this case. |
| 1108 | */ |
| 1109 | if (unlikely(!offset)) |
| 1110 | offset = p->dma_read(CDSA, lch); |
| 1111 | } |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1112 | |
| 1113 | if (cpu_class_is_omap1()) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1114 | offset |= (p->dma_read(CDSA, lch) & 0xFFFF0000); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1115 | |
| 1116 | return offset; |
| 1117 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1118 | EXPORT_SYMBOL(omap_get_dma_dst_pos); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1119 | |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1120 | int omap_get_dma_active_status(int lch) |
| 1121 | { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1122 | return (p->dma_read(CCR, lch) & OMAP_DMA_CCR_EN) != 0; |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1123 | } |
| 1124 | EXPORT_SYMBOL(omap_get_dma_active_status); |
| 1125 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1126 | int omap_dma_running(void) |
| 1127 | { |
| 1128 | int lch; |
| 1129 | |
Janusz Krzysztofik | f8e9e98 | 2009-12-11 16:16:33 -0800 | [diff] [blame] | 1130 | if (cpu_class_is_omap1()) |
| 1131 | if (omap_lcd_dma_running()) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1132 | return 1; |
| 1133 | |
| 1134 | for (lch = 0; lch < dma_chan_count; lch++) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1135 | if (p->dma_read(CCR, lch) & OMAP_DMA_CCR_EN) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1136 | return 1; |
| 1137 | |
| 1138 | return 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /* |
| 1142 | * lch_queue DMA will start right after lch_head one is finished. |
| 1143 | * For this DMA link to start, you still need to start (see omap_start_dma) |
| 1144 | * the first one. That will fire up the entire queue. |
| 1145 | */ |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1146 | void omap_dma_link_lch(int lch_head, int lch_queue) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1147 | { |
| 1148 | if (omap_dma_in_1510_mode()) { |
Janusz Krzysztofik | 9f0f4ae | 2009-08-23 17:56:12 +0200 | [diff] [blame] | 1149 | if (lch_head == lch_queue) { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1150 | p->dma_write(p->dma_read(CCR, lch_head) | (3 << 8), |
G, Manjunath Kondaiah | a4c537c7 | 2010-12-20 18:27:17 -0800 | [diff] [blame] | 1151 | CCR, lch_head); |
Janusz Krzysztofik | 9f0f4ae | 2009-08-23 17:56:12 +0200 | [diff] [blame] | 1152 | return; |
| 1153 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1154 | printk(KERN_ERR "DMA linking is not supported in 1510 mode\n"); |
| 1155 | BUG(); |
| 1156 | return; |
| 1157 | } |
| 1158 | |
| 1159 | if ((dma_chan[lch_head].dev_id == -1) || |
| 1160 | (dma_chan[lch_queue].dev_id == -1)) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 1161 | pr_err("omap_dma: trying to link non requested channels\n"); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1162 | dump_stack(); |
| 1163 | } |
| 1164 | |
| 1165 | dma_chan[lch_head].next_lch = lch_queue; |
| 1166 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1167 | EXPORT_SYMBOL(omap_dma_link_lch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1168 | |
| 1169 | /* |
| 1170 | * Once the DMA queue is stopped, we can destroy it. |
| 1171 | */ |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1172 | void omap_dma_unlink_lch(int lch_head, int lch_queue) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1173 | { |
| 1174 | if (omap_dma_in_1510_mode()) { |
Janusz Krzysztofik | 9f0f4ae | 2009-08-23 17:56:12 +0200 | [diff] [blame] | 1175 | if (lch_head == lch_queue) { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1176 | p->dma_write(p->dma_read(CCR, lch_head) & ~(3 << 8), |
G, Manjunath Kondaiah | a4c537c7 | 2010-12-20 18:27:17 -0800 | [diff] [blame] | 1177 | CCR, lch_head); |
Janusz Krzysztofik | 9f0f4ae | 2009-08-23 17:56:12 +0200 | [diff] [blame] | 1178 | return; |
| 1179 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1180 | printk(KERN_ERR "DMA linking is not supported in 1510 mode\n"); |
| 1181 | BUG(); |
| 1182 | return; |
| 1183 | } |
| 1184 | |
| 1185 | if (dma_chan[lch_head].next_lch != lch_queue || |
| 1186 | dma_chan[lch_head].next_lch == -1) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 1187 | pr_err("omap_dma: trying to unlink non linked channels\n"); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1188 | dump_stack(); |
| 1189 | } |
| 1190 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1191 | if ((dma_chan[lch_head].flags & OMAP_DMA_ACTIVE) || |
Roel Kluin | 247421f | 2010-01-13 18:10:29 -0800 | [diff] [blame] | 1192 | (dma_chan[lch_queue].flags & OMAP_DMA_ACTIVE)) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 1193 | pr_err("omap_dma: You need to stop the DMA channels before unlinking\n"); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1194 | dump_stack(); |
| 1195 | } |
| 1196 | |
| 1197 | dma_chan[lch_head].next_lch = -1; |
| 1198 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1199 | EXPORT_SYMBOL(omap_dma_unlink_lch); |
| 1200 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1201 | #ifndef CONFIG_ARCH_OMAP1 |
| 1202 | /* Create chain of DMA channesls */ |
| 1203 | static void create_dma_lch_chain(int lch_head, int lch_queue) |
| 1204 | { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1205 | u32 l; |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1206 | |
| 1207 | /* Check if this is the first link in chain */ |
| 1208 | if (dma_chan[lch_head].next_linked_ch == -1) { |
| 1209 | dma_chan[lch_head].next_linked_ch = lch_queue; |
| 1210 | dma_chan[lch_head].prev_linked_ch = lch_queue; |
| 1211 | dma_chan[lch_queue].next_linked_ch = lch_head; |
| 1212 | dma_chan[lch_queue].prev_linked_ch = lch_head; |
| 1213 | } |
| 1214 | |
| 1215 | /* a link exists, link the new channel in circular chain */ |
| 1216 | else { |
| 1217 | dma_chan[lch_queue].next_linked_ch = |
| 1218 | dma_chan[lch_head].next_linked_ch; |
| 1219 | dma_chan[lch_queue].prev_linked_ch = lch_head; |
| 1220 | dma_chan[lch_head].next_linked_ch = lch_queue; |
| 1221 | dma_chan[dma_chan[lch_queue].next_linked_ch].prev_linked_ch = |
| 1222 | lch_queue; |
| 1223 | } |
| 1224 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1225 | l = p->dma_read(CLNK_CTRL, lch_head); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1226 | l &= ~(0x1f); |
| 1227 | l |= lch_queue; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1228 | p->dma_write(l, CLNK_CTRL, lch_head); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1229 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1230 | l = p->dma_read(CLNK_CTRL, lch_queue); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1231 | l &= ~(0x1f); |
| 1232 | l |= (dma_chan[lch_queue].next_linked_ch); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1233 | p->dma_write(l, CLNK_CTRL, lch_queue); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | /** |
| 1237 | * @brief omap_request_dma_chain : Request a chain of DMA channels |
| 1238 | * |
| 1239 | * @param dev_id - Device id using the dma channel |
| 1240 | * @param dev_name - Device name |
| 1241 | * @param callback - Call back function |
| 1242 | * @chain_id - |
| 1243 | * @no_of_chans - Number of channels requested |
| 1244 | * @chain_mode - Dynamic or static chaining : OMAP_DMA_STATIC_CHAIN |
| 1245 | * OMAP_DMA_DYNAMIC_CHAIN |
| 1246 | * @params - Channel parameters |
| 1247 | * |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1248 | * @return - Success : 0 |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1249 | * Failure: -EINVAL/-ENOMEM |
| 1250 | */ |
| 1251 | int omap_request_dma_chain(int dev_id, const char *dev_name, |
Santosh Shilimkar | 279b918d | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 1252 | void (*callback) (int lch, u16 ch_status, |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1253 | void *data), |
| 1254 | int *chain_id, int no_of_chans, int chain_mode, |
| 1255 | struct omap_dma_channel_params params) |
| 1256 | { |
| 1257 | int *channels; |
| 1258 | int i, err; |
| 1259 | |
| 1260 | /* Is the chain mode valid ? */ |
| 1261 | if (chain_mode != OMAP_DMA_STATIC_CHAIN |
| 1262 | && chain_mode != OMAP_DMA_DYNAMIC_CHAIN) { |
| 1263 | printk(KERN_ERR "Invalid chain mode requested\n"); |
| 1264 | return -EINVAL; |
| 1265 | } |
| 1266 | |
| 1267 | if (unlikely((no_of_chans < 1 |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 1268 | || no_of_chans > dma_lch_count))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1269 | printk(KERN_ERR "Invalid Number of channels requested\n"); |
| 1270 | return -EINVAL; |
| 1271 | } |
| 1272 | |
manjugk manjugk | ea221a6 | 2010-05-14 12:05:25 -0700 | [diff] [blame] | 1273 | /* |
| 1274 | * Allocate a queue to maintain the status of the channels |
| 1275 | * in the chain |
| 1276 | */ |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1277 | channels = kmalloc(sizeof(*channels) * no_of_chans, GFP_KERNEL); |
| 1278 | if (channels == NULL) { |
| 1279 | printk(KERN_ERR "omap_dma: No memory for channel queue\n"); |
| 1280 | return -ENOMEM; |
| 1281 | } |
| 1282 | |
| 1283 | /* request and reserve DMA channels for the chain */ |
| 1284 | for (i = 0; i < no_of_chans; i++) { |
| 1285 | err = omap_request_dma(dev_id, dev_name, |
Russell King | c0fc18c5 | 2008-09-05 15:10:27 +0100 | [diff] [blame] | 1286 | callback, NULL, &channels[i]); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1287 | if (err < 0) { |
| 1288 | int j; |
| 1289 | for (j = 0; j < i; j++) |
| 1290 | omap_free_dma(channels[j]); |
| 1291 | kfree(channels); |
| 1292 | printk(KERN_ERR "omap_dma: Request failed %d\n", err); |
| 1293 | return err; |
| 1294 | } |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1295 | dma_chan[channels[i]].prev_linked_ch = -1; |
| 1296 | dma_chan[channels[i]].state = DMA_CH_NOTSTARTED; |
| 1297 | |
| 1298 | /* |
| 1299 | * Allowing client drivers to set common parameters now, |
| 1300 | * so that later only relevant (src_start, dest_start |
| 1301 | * and element count) can be set |
| 1302 | */ |
| 1303 | omap_set_dma_params(channels[i], ¶ms); |
| 1304 | } |
| 1305 | |
| 1306 | *chain_id = channels[0]; |
| 1307 | dma_linked_lch[*chain_id].linked_dmach_q = channels; |
| 1308 | dma_linked_lch[*chain_id].chain_mode = chain_mode; |
| 1309 | dma_linked_lch[*chain_id].chain_state = DMA_CHAIN_NOTSTARTED; |
| 1310 | dma_linked_lch[*chain_id].no_of_lchs_linked = no_of_chans; |
| 1311 | |
| 1312 | for (i = 0; i < no_of_chans; i++) |
| 1313 | dma_chan[channels[i]].chain_id = *chain_id; |
| 1314 | |
| 1315 | /* Reset the Queue pointers */ |
| 1316 | OMAP_DMA_CHAIN_QINIT(*chain_id); |
| 1317 | |
| 1318 | /* Set up the chain */ |
| 1319 | if (no_of_chans == 1) |
| 1320 | create_dma_lch_chain(channels[0], channels[0]); |
| 1321 | else { |
| 1322 | for (i = 0; i < (no_of_chans - 1); i++) |
| 1323 | create_dma_lch_chain(channels[i], channels[i + 1]); |
| 1324 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1325 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1326 | return 0; |
| 1327 | } |
| 1328 | EXPORT_SYMBOL(omap_request_dma_chain); |
| 1329 | |
| 1330 | /** |
| 1331 | * @brief omap_modify_dma_chain_param : Modify the chain's params - Modify the |
| 1332 | * params after setting it. Dont do this while dma is running!! |
| 1333 | * |
| 1334 | * @param chain_id - Chained logical channel id. |
| 1335 | * @param params |
| 1336 | * |
| 1337 | * @return - Success : 0 |
| 1338 | * Failure : -EINVAL |
| 1339 | */ |
| 1340 | int omap_modify_dma_chain_params(int chain_id, |
| 1341 | struct omap_dma_channel_params params) |
| 1342 | { |
| 1343 | int *channels; |
| 1344 | u32 i; |
| 1345 | |
| 1346 | /* Check for input params */ |
| 1347 | if (unlikely((chain_id < 0 |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 1348 | || chain_id >= dma_lch_count))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1349 | printk(KERN_ERR "Invalid chain id\n"); |
| 1350 | return -EINVAL; |
| 1351 | } |
| 1352 | |
| 1353 | /* Check if the chain exists */ |
| 1354 | if (dma_linked_lch[chain_id].linked_dmach_q == NULL) { |
| 1355 | printk(KERN_ERR "Chain doesn't exists\n"); |
| 1356 | return -EINVAL; |
| 1357 | } |
| 1358 | channels = dma_linked_lch[chain_id].linked_dmach_q; |
| 1359 | |
| 1360 | for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) { |
| 1361 | /* |
| 1362 | * Allowing client drivers to set common parameters now, |
| 1363 | * so that later only relevant (src_start, dest_start |
| 1364 | * and element count) can be set |
| 1365 | */ |
| 1366 | omap_set_dma_params(channels[i], ¶ms); |
| 1367 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1368 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1369 | return 0; |
| 1370 | } |
| 1371 | EXPORT_SYMBOL(omap_modify_dma_chain_params); |
| 1372 | |
| 1373 | /** |
| 1374 | * @brief omap_free_dma_chain - Free all the logical channels in a chain. |
| 1375 | * |
| 1376 | * @param chain_id |
| 1377 | * |
| 1378 | * @return - Success : 0 |
| 1379 | * Failure : -EINVAL |
| 1380 | */ |
| 1381 | int omap_free_dma_chain(int chain_id) |
| 1382 | { |
| 1383 | int *channels; |
| 1384 | u32 i; |
| 1385 | |
| 1386 | /* Check for input params */ |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 1387 | if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1388 | printk(KERN_ERR "Invalid chain id\n"); |
| 1389 | return -EINVAL; |
| 1390 | } |
| 1391 | |
| 1392 | /* Check if the chain exists */ |
| 1393 | if (dma_linked_lch[chain_id].linked_dmach_q == NULL) { |
| 1394 | printk(KERN_ERR "Chain doesn't exists\n"); |
| 1395 | return -EINVAL; |
| 1396 | } |
| 1397 | |
| 1398 | channels = dma_linked_lch[chain_id].linked_dmach_q; |
| 1399 | for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) { |
| 1400 | dma_chan[channels[i]].next_linked_ch = -1; |
| 1401 | dma_chan[channels[i]].prev_linked_ch = -1; |
| 1402 | dma_chan[channels[i]].chain_id = -1; |
| 1403 | dma_chan[channels[i]].state = DMA_CH_NOTSTARTED; |
| 1404 | omap_free_dma(channels[i]); |
| 1405 | } |
| 1406 | |
| 1407 | kfree(channels); |
| 1408 | |
| 1409 | dma_linked_lch[chain_id].linked_dmach_q = NULL; |
| 1410 | dma_linked_lch[chain_id].chain_mode = -1; |
| 1411 | dma_linked_lch[chain_id].chain_state = -1; |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1412 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1413 | return (0); |
| 1414 | } |
| 1415 | EXPORT_SYMBOL(omap_free_dma_chain); |
| 1416 | |
| 1417 | /** |
| 1418 | * @brief omap_dma_chain_status - Check if the chain is in |
| 1419 | * active / inactive state. |
| 1420 | * @param chain_id |
| 1421 | * |
| 1422 | * @return - Success : OMAP_DMA_CHAIN_ACTIVE/OMAP_DMA_CHAIN_INACTIVE |
| 1423 | * Failure : -EINVAL |
| 1424 | */ |
| 1425 | int omap_dma_chain_status(int chain_id) |
| 1426 | { |
| 1427 | /* Check for input params */ |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 1428 | if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1429 | printk(KERN_ERR "Invalid chain id\n"); |
| 1430 | return -EINVAL; |
| 1431 | } |
| 1432 | |
| 1433 | /* Check if the chain exists */ |
| 1434 | if (dma_linked_lch[chain_id].linked_dmach_q == NULL) { |
| 1435 | printk(KERN_ERR "Chain doesn't exists\n"); |
| 1436 | return -EINVAL; |
| 1437 | } |
| 1438 | pr_debug("CHAINID=%d, qcnt=%d\n", chain_id, |
| 1439 | dma_linked_lch[chain_id].q_count); |
| 1440 | |
| 1441 | if (OMAP_DMA_CHAIN_QEMPTY(chain_id)) |
| 1442 | return OMAP_DMA_CHAIN_INACTIVE; |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1443 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1444 | return OMAP_DMA_CHAIN_ACTIVE; |
| 1445 | } |
| 1446 | EXPORT_SYMBOL(omap_dma_chain_status); |
| 1447 | |
| 1448 | /** |
| 1449 | * @brief omap_dma_chain_a_transfer - Get a free channel from a chain, |
| 1450 | * set the params and start the transfer. |
| 1451 | * |
| 1452 | * @param chain_id |
| 1453 | * @param src_start - buffer start address |
| 1454 | * @param dest_start - Dest address |
| 1455 | * @param elem_count |
| 1456 | * @param frame_count |
| 1457 | * @param callbk_data - channel callback parameter data. |
| 1458 | * |
Anand Gadiyar | f4b6a7e | 2008-03-11 01:10:35 +0530 | [diff] [blame] | 1459 | * @return - Success : 0 |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1460 | * Failure: -EINVAL/-EBUSY |
| 1461 | */ |
| 1462 | int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start, |
| 1463 | int elem_count, int frame_count, void *callbk_data) |
| 1464 | { |
| 1465 | int *channels; |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1466 | u32 l, lch; |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1467 | int start_dma = 0; |
| 1468 | |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1469 | /* |
| 1470 | * if buffer size is less than 1 then there is |
| 1471 | * no use of starting the chain |
| 1472 | */ |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1473 | if (elem_count < 1) { |
| 1474 | printk(KERN_ERR "Invalid buffer size\n"); |
| 1475 | return -EINVAL; |
| 1476 | } |
| 1477 | |
| 1478 | /* Check for input params */ |
| 1479 | if (unlikely((chain_id < 0 |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 1480 | || chain_id >= dma_lch_count))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1481 | printk(KERN_ERR "Invalid chain id\n"); |
| 1482 | return -EINVAL; |
| 1483 | } |
| 1484 | |
| 1485 | /* Check if the chain exists */ |
| 1486 | if (dma_linked_lch[chain_id].linked_dmach_q == NULL) { |
| 1487 | printk(KERN_ERR "Chain doesn't exist\n"); |
| 1488 | return -EINVAL; |
| 1489 | } |
| 1490 | |
| 1491 | /* Check if all the channels in chain are in use */ |
| 1492 | if (OMAP_DMA_CHAIN_QFULL(chain_id)) |
| 1493 | return -EBUSY; |
| 1494 | |
| 1495 | /* Frame count may be negative in case of indexed transfers */ |
| 1496 | channels = dma_linked_lch[chain_id].linked_dmach_q; |
| 1497 | |
| 1498 | /* Get a free channel */ |
| 1499 | lch = channels[dma_linked_lch[chain_id].q_tail]; |
| 1500 | |
| 1501 | /* Store the callback data */ |
| 1502 | dma_chan[lch].data = callbk_data; |
| 1503 | |
| 1504 | /* Increment the q_tail */ |
| 1505 | OMAP_DMA_CHAIN_INCQTAIL(chain_id); |
| 1506 | |
| 1507 | /* Set the params to the free channel */ |
| 1508 | if (src_start != 0) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1509 | p->dma_write(src_start, CSSA, lch); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1510 | if (dest_start != 0) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1511 | p->dma_write(dest_start, CDSA, lch); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1512 | |
| 1513 | /* Write the buffer size */ |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1514 | p->dma_write(elem_count, CEN, lch); |
| 1515 | p->dma_write(frame_count, CFN, lch); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1516 | |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1517 | /* |
| 1518 | * If the chain is dynamically linked, |
| 1519 | * then we may have to start the chain if its not active |
| 1520 | */ |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1521 | if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_DYNAMIC_CHAIN) { |
| 1522 | |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1523 | /* |
| 1524 | * In Dynamic chain, if the chain is not started, |
| 1525 | * queue the channel |
| 1526 | */ |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1527 | if (dma_linked_lch[chain_id].chain_state == |
| 1528 | DMA_CHAIN_NOTSTARTED) { |
| 1529 | /* Enable the link in previous channel */ |
| 1530 | if (dma_chan[dma_chan[lch].prev_linked_ch].state == |
| 1531 | DMA_CH_QUEUED) |
| 1532 | enable_lnk(dma_chan[lch].prev_linked_ch); |
| 1533 | dma_chan[lch].state = DMA_CH_QUEUED; |
| 1534 | } |
| 1535 | |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1536 | /* |
| 1537 | * Chain is already started, make sure its active, |
| 1538 | * if not then start the chain |
| 1539 | */ |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1540 | else { |
| 1541 | start_dma = 1; |
| 1542 | |
| 1543 | if (dma_chan[dma_chan[lch].prev_linked_ch].state == |
| 1544 | DMA_CH_STARTED) { |
| 1545 | enable_lnk(dma_chan[lch].prev_linked_ch); |
| 1546 | dma_chan[lch].state = DMA_CH_QUEUED; |
| 1547 | start_dma = 0; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1548 | if (0 == ((1 << 7) & p->dma_read( |
G, Manjunath Kondaiah | a4c537c7 | 2010-12-20 18:27:17 -0800 | [diff] [blame] | 1549 | CCR, dma_chan[lch].prev_linked_ch))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1550 | disable_lnk(dma_chan[lch]. |
| 1551 | prev_linked_ch); |
| 1552 | pr_debug("\n prev ch is stopped\n"); |
| 1553 | start_dma = 1; |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | else if (dma_chan[dma_chan[lch].prev_linked_ch].state |
| 1558 | == DMA_CH_QUEUED) { |
| 1559 | enable_lnk(dma_chan[lch].prev_linked_ch); |
| 1560 | dma_chan[lch].state = DMA_CH_QUEUED; |
| 1561 | start_dma = 0; |
| 1562 | } |
| 1563 | omap_enable_channel_irq(lch); |
| 1564 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1565 | l = p->dma_read(CCR, lch); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1566 | |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1567 | if ((0 == (l & (1 << 24)))) |
| 1568 | l &= ~(1 << 25); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1569 | else |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1570 | l |= (1 << 25); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1571 | if (start_dma == 1) { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1572 | if (0 == (l & (1 << 7))) { |
| 1573 | l |= (1 << 7); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1574 | dma_chan[lch].state = DMA_CH_STARTED; |
| 1575 | pr_debug("starting %d\n", lch); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1576 | p->dma_write(l, CCR, lch); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1577 | } else |
| 1578 | start_dma = 0; |
| 1579 | } else { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1580 | if (0 == (l & (1 << 7))) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1581 | p->dma_write(l, CCR, lch); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1582 | } |
| 1583 | dma_chan[lch].flags |= OMAP_DMA_ACTIVE; |
| 1584 | } |
| 1585 | } |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1586 | |
Anand Gadiyar | f4b6a7e | 2008-03-11 01:10:35 +0530 | [diff] [blame] | 1587 | return 0; |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1588 | } |
| 1589 | EXPORT_SYMBOL(omap_dma_chain_a_transfer); |
| 1590 | |
| 1591 | /** |
| 1592 | * @brief omap_start_dma_chain_transfers - Start the chain |
| 1593 | * |
| 1594 | * @param chain_id |
| 1595 | * |
| 1596 | * @return - Success : 0 |
| 1597 | * Failure : -EINVAL/-EBUSY |
| 1598 | */ |
| 1599 | int omap_start_dma_chain_transfers(int chain_id) |
| 1600 | { |
| 1601 | int *channels; |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1602 | u32 l, i; |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1603 | |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 1604 | if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1605 | printk(KERN_ERR "Invalid chain id\n"); |
| 1606 | return -EINVAL; |
| 1607 | } |
| 1608 | |
| 1609 | channels = dma_linked_lch[chain_id].linked_dmach_q; |
| 1610 | |
| 1611 | if (dma_linked_lch[channels[0]].chain_state == DMA_CHAIN_STARTED) { |
| 1612 | printk(KERN_ERR "Chain is already started\n"); |
| 1613 | return -EBUSY; |
| 1614 | } |
| 1615 | |
| 1616 | if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_STATIC_CHAIN) { |
| 1617 | for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; |
| 1618 | i++) { |
| 1619 | enable_lnk(channels[i]); |
| 1620 | omap_enable_channel_irq(channels[i]); |
| 1621 | } |
| 1622 | } else { |
| 1623 | omap_enable_channel_irq(channels[0]); |
| 1624 | } |
| 1625 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1626 | l = p->dma_read(CCR, channels[0]); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1627 | l |= (1 << 7); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1628 | dma_linked_lch[chain_id].chain_state = DMA_CHAIN_STARTED; |
| 1629 | dma_chan[channels[0]].state = DMA_CH_STARTED; |
| 1630 | |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1631 | if ((0 == (l & (1 << 24)))) |
| 1632 | l &= ~(1 << 25); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1633 | else |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1634 | l |= (1 << 25); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1635 | p->dma_write(l, CCR, channels[0]); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1636 | |
| 1637 | dma_chan[channels[0]].flags |= OMAP_DMA_ACTIVE; |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1638 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1639 | return 0; |
| 1640 | } |
| 1641 | EXPORT_SYMBOL(omap_start_dma_chain_transfers); |
| 1642 | |
| 1643 | /** |
| 1644 | * @brief omap_stop_dma_chain_transfers - Stop the dma transfer of a chain. |
| 1645 | * |
| 1646 | * @param chain_id |
| 1647 | * |
| 1648 | * @return - Success : 0 |
| 1649 | * Failure : EINVAL |
| 1650 | */ |
| 1651 | int omap_stop_dma_chain_transfers(int chain_id) |
| 1652 | { |
| 1653 | int *channels; |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1654 | u32 l, i; |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 1655 | u32 sys_cf = 0; |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1656 | |
| 1657 | /* Check for input params */ |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 1658 | if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1659 | printk(KERN_ERR "Invalid chain id\n"); |
| 1660 | return -EINVAL; |
| 1661 | } |
| 1662 | |
| 1663 | /* Check if the chain exists */ |
| 1664 | if (dma_linked_lch[chain_id].linked_dmach_q == NULL) { |
| 1665 | printk(KERN_ERR "Chain doesn't exists\n"); |
| 1666 | return -EINVAL; |
| 1667 | } |
| 1668 | channels = dma_linked_lch[chain_id].linked_dmach_q; |
| 1669 | |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 1670 | if (IS_DMA_ERRATA(DMA_ERRATA_i88)) { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1671 | sys_cf = p->dma_read(OCP_SYSCONFIG, 0); |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 1672 | l = sys_cf; |
| 1673 | /* Middle mode reg set no Standby */ |
| 1674 | l &= ~((1 << 12)|(1 << 13)); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1675 | p->dma_write(l, OCP_SYSCONFIG, 0); |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 1676 | } |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1677 | |
| 1678 | for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) { |
| 1679 | |
| 1680 | /* Stop the Channel transmission */ |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1681 | l = p->dma_read(CCR, channels[i]); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1682 | l &= ~(1 << 7); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1683 | p->dma_write(l, CCR, channels[i]); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1684 | |
| 1685 | /* Disable the link in all the channels */ |
| 1686 | disable_lnk(channels[i]); |
| 1687 | dma_chan[channels[i]].state = DMA_CH_NOTSTARTED; |
| 1688 | |
| 1689 | } |
| 1690 | dma_linked_lch[chain_id].chain_state = DMA_CHAIN_NOTSTARTED; |
| 1691 | |
| 1692 | /* Reset the Queue pointers */ |
| 1693 | OMAP_DMA_CHAIN_QINIT(chain_id); |
| 1694 | |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 1695 | if (IS_DMA_ERRATA(DMA_ERRATA_i88)) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1696 | p->dma_write(sys_cf, OCP_SYSCONFIG, 0); |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1697 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1698 | return 0; |
| 1699 | } |
| 1700 | EXPORT_SYMBOL(omap_stop_dma_chain_transfers); |
| 1701 | |
| 1702 | /* Get the index of the ongoing DMA in chain */ |
| 1703 | /** |
| 1704 | * @brief omap_get_dma_chain_index - Get the element and frame index |
| 1705 | * of the ongoing DMA in chain |
| 1706 | * |
| 1707 | * @param chain_id |
| 1708 | * @param ei - Element index |
| 1709 | * @param fi - Frame index |
| 1710 | * |
| 1711 | * @return - Success : 0 |
| 1712 | * Failure : -EINVAL |
| 1713 | */ |
| 1714 | int omap_get_dma_chain_index(int chain_id, int *ei, int *fi) |
| 1715 | { |
| 1716 | int lch; |
| 1717 | int *channels; |
| 1718 | |
| 1719 | /* Check for input params */ |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 1720 | if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1721 | printk(KERN_ERR "Invalid chain id\n"); |
| 1722 | return -EINVAL; |
| 1723 | } |
| 1724 | |
| 1725 | /* Check if the chain exists */ |
| 1726 | if (dma_linked_lch[chain_id].linked_dmach_q == NULL) { |
| 1727 | printk(KERN_ERR "Chain doesn't exists\n"); |
| 1728 | return -EINVAL; |
| 1729 | } |
| 1730 | if ((!ei) || (!fi)) |
| 1731 | return -EINVAL; |
| 1732 | |
| 1733 | channels = dma_linked_lch[chain_id].linked_dmach_q; |
| 1734 | |
| 1735 | /* Get the current channel */ |
| 1736 | lch = channels[dma_linked_lch[chain_id].q_head]; |
| 1737 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1738 | *ei = p->dma_read(CCEN, lch); |
| 1739 | *fi = p->dma_read(CCFN, lch); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1740 | |
| 1741 | return 0; |
| 1742 | } |
| 1743 | EXPORT_SYMBOL(omap_get_dma_chain_index); |
| 1744 | |
| 1745 | /** |
| 1746 | * @brief omap_get_dma_chain_dst_pos - Get the destination position of the |
| 1747 | * ongoing DMA in chain |
| 1748 | * |
| 1749 | * @param chain_id |
| 1750 | * |
| 1751 | * @return - Success : Destination position |
| 1752 | * Failure : -EINVAL |
| 1753 | */ |
| 1754 | int omap_get_dma_chain_dst_pos(int chain_id) |
| 1755 | { |
| 1756 | int lch; |
| 1757 | int *channels; |
| 1758 | |
| 1759 | /* Check for input params */ |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 1760 | if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1761 | printk(KERN_ERR "Invalid chain id\n"); |
| 1762 | return -EINVAL; |
| 1763 | } |
| 1764 | |
| 1765 | /* Check if the chain exists */ |
| 1766 | if (dma_linked_lch[chain_id].linked_dmach_q == NULL) { |
| 1767 | printk(KERN_ERR "Chain doesn't exists\n"); |
| 1768 | return -EINVAL; |
| 1769 | } |
| 1770 | |
| 1771 | channels = dma_linked_lch[chain_id].linked_dmach_q; |
| 1772 | |
| 1773 | /* Get the current channel */ |
| 1774 | lch = channels[dma_linked_lch[chain_id].q_head]; |
| 1775 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1776 | return p->dma_read(CDAC, lch); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1777 | } |
| 1778 | EXPORT_SYMBOL(omap_get_dma_chain_dst_pos); |
| 1779 | |
| 1780 | /** |
| 1781 | * @brief omap_get_dma_chain_src_pos - Get the source position |
| 1782 | * of the ongoing DMA in chain |
| 1783 | * @param chain_id |
| 1784 | * |
| 1785 | * @return - Success : Destination position |
| 1786 | * Failure : -EINVAL |
| 1787 | */ |
| 1788 | int omap_get_dma_chain_src_pos(int chain_id) |
| 1789 | { |
| 1790 | int lch; |
| 1791 | int *channels; |
| 1792 | |
| 1793 | /* Check for input params */ |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 1794 | if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) { |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1795 | printk(KERN_ERR "Invalid chain id\n"); |
| 1796 | return -EINVAL; |
| 1797 | } |
| 1798 | |
| 1799 | /* Check if the chain exists */ |
| 1800 | if (dma_linked_lch[chain_id].linked_dmach_q == NULL) { |
| 1801 | printk(KERN_ERR "Chain doesn't exists\n"); |
| 1802 | return -EINVAL; |
| 1803 | } |
| 1804 | |
| 1805 | channels = dma_linked_lch[chain_id].linked_dmach_q; |
| 1806 | |
| 1807 | /* Get the current channel */ |
| 1808 | lch = channels[dma_linked_lch[chain_id].q_head]; |
| 1809 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1810 | return p->dma_read(CSAC, lch); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1811 | } |
| 1812 | EXPORT_SYMBOL(omap_get_dma_chain_src_pos); |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1813 | #endif /* ifndef CONFIG_ARCH_OMAP1 */ |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1814 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1815 | /*----------------------------------------------------------------------------*/ |
| 1816 | |
| 1817 | #ifdef CONFIG_ARCH_OMAP1 |
| 1818 | |
| 1819 | static int omap1_dma_handle_ch(int ch) |
| 1820 | { |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 1821 | u32 csr; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1822 | |
| 1823 | if (enable_1510_mode && ch >= 6) { |
| 1824 | csr = dma_chan[ch].saved_csr; |
| 1825 | dma_chan[ch].saved_csr = 0; |
| 1826 | } else |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1827 | csr = p->dma_read(CSR, ch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1828 | if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) { |
| 1829 | dma_chan[ch + 6].saved_csr = csr >> 7; |
| 1830 | csr &= 0x7f; |
| 1831 | } |
| 1832 | if ((csr & 0x3f) == 0) |
| 1833 | return 0; |
| 1834 | if (unlikely(dma_chan[ch].dev_id == -1)) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 1835 | pr_warn("Spurious interrupt from DMA channel %d (CSR %04x)\n", |
| 1836 | ch, csr); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1837 | return 0; |
| 1838 | } |
Tony Lindgren | 7ff879d | 2006-06-26 16:16:15 -0700 | [diff] [blame] | 1839 | if (unlikely(csr & OMAP1_DMA_TOUT_IRQ)) |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 1840 | pr_warn("DMA timeout with device %d\n", dma_chan[ch].dev_id); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1841 | if (unlikely(csr & OMAP_DMA_DROP_IRQ)) |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 1842 | pr_warn("DMA synchronization event drop occurred with device %d\n", |
| 1843 | dma_chan[ch].dev_id); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1844 | if (likely(csr & OMAP_DMA_BLOCK_IRQ)) |
| 1845 | dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE; |
| 1846 | if (likely(dma_chan[ch].callback != NULL)) |
| 1847 | dma_chan[ch].callback(ch, csr, dma_chan[ch].data); |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 1848 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1849 | return 1; |
| 1850 | } |
| 1851 | |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 1852 | static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1853 | { |
| 1854 | int ch = ((int) dev_id) - 1; |
| 1855 | int handled = 0; |
| 1856 | |
| 1857 | for (;;) { |
| 1858 | int handled_now = 0; |
| 1859 | |
| 1860 | handled_now += omap1_dma_handle_ch(ch); |
| 1861 | if (enable_1510_mode && dma_chan[ch + 6].saved_csr) |
| 1862 | handled_now += omap1_dma_handle_ch(ch + 6); |
| 1863 | if (!handled_now) |
| 1864 | break; |
| 1865 | handled += handled_now; |
| 1866 | } |
| 1867 | |
| 1868 | return handled ? IRQ_HANDLED : IRQ_NONE; |
| 1869 | } |
| 1870 | |
| 1871 | #else |
| 1872 | #define omap1_dma_irq_handler NULL |
| 1873 | #endif |
| 1874 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1875 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1876 | |
| 1877 | static int omap2_dma_handle_ch(int ch) |
| 1878 | { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1879 | u32 status = p->dma_read(CSR, ch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1880 | |
Juha Yrjola | 3151369 | 2006-12-06 17:13:47 -0800 | [diff] [blame] | 1881 | if (!status) { |
| 1882 | if (printk_ratelimit()) |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 1883 | pr_warn("Spurious DMA IRQ for lch %d\n", ch); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1884 | p->dma_write(1 << ch, IRQSTATUS_L0, ch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1885 | return 0; |
Juha Yrjola | 3151369 | 2006-12-06 17:13:47 -0800 | [diff] [blame] | 1886 | } |
| 1887 | if (unlikely(dma_chan[ch].dev_id == -1)) { |
| 1888 | if (printk_ratelimit()) |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 1889 | pr_warn("IRQ %04x for non-allocated DMA channel %d\n", |
| 1890 | status, ch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1891 | return 0; |
Juha Yrjola | 3151369 | 2006-12-06 17:13:47 -0800 | [diff] [blame] | 1892 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1893 | if (unlikely(status & OMAP_DMA_DROP_IRQ)) |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 1894 | pr_info("DMA synchronization event drop occurred with device %d\n", |
| 1895 | dma_chan[ch].dev_id); |
Santosh Shilimkar | a50f18c | 2008-12-10 17:36:53 -0800 | [diff] [blame] | 1896 | if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ)) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1897 | printk(KERN_INFO "DMA transaction error with device %d\n", |
| 1898 | dma_chan[ch].dev_id); |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 1899 | if (IS_DMA_ERRATA(DMA_ERRATA_i378)) { |
Santosh Shilimkar | a50f18c | 2008-12-10 17:36:53 -0800 | [diff] [blame] | 1900 | u32 ccr; |
| 1901 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1902 | ccr = p->dma_read(CCR, ch); |
Santosh Shilimkar | a50f18c | 2008-12-10 17:36:53 -0800 | [diff] [blame] | 1903 | ccr &= ~OMAP_DMA_CCR_EN; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1904 | p->dma_write(ccr, CCR, ch); |
Santosh Shilimkar | a50f18c | 2008-12-10 17:36:53 -0800 | [diff] [blame] | 1905 | dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE; |
| 1906 | } |
| 1907 | } |
Tony Lindgren | 7ff879d | 2006-06-26 16:16:15 -0700 | [diff] [blame] | 1908 | if (unlikely(status & OMAP2_DMA_SECURE_ERR_IRQ)) |
| 1909 | printk(KERN_INFO "DMA secure error with device %d\n", |
| 1910 | dma_chan[ch].dev_id); |
| 1911 | if (unlikely(status & OMAP2_DMA_MISALIGNED_ERR_IRQ)) |
| 1912 | printk(KERN_INFO "DMA misaligned error with device %d\n", |
| 1913 | dma_chan[ch].dev_id); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1914 | |
Adrian Hunter | 4fb699b | 2010-11-24 13:23:21 +0200 | [diff] [blame] | 1915 | p->dma_write(status, CSR, ch); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1916 | p->dma_write(1 << ch, IRQSTATUS_L0, ch); |
Mathias Nyman | e860e6d | 2010-10-25 14:35:24 +0000 | [diff] [blame] | 1917 | /* read back the register to flush the write */ |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1918 | p->dma_read(IRQSTATUS_L0, ch); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1919 | |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1920 | /* If the ch is not chained then chain_id will be -1 */ |
| 1921 | if (dma_chan[ch].chain_id != -1) { |
| 1922 | int chain_id = dma_chan[ch].chain_id; |
| 1923 | dma_chan[ch].state = DMA_CH_NOTSTARTED; |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1924 | if (p->dma_read(CLNK_CTRL, ch) & (1 << 15)) |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1925 | dma_chan[dma_chan[ch].next_linked_ch].state = |
| 1926 | DMA_CH_STARTED; |
| 1927 | if (dma_linked_lch[chain_id].chain_mode == |
| 1928 | OMAP_DMA_DYNAMIC_CHAIN) |
| 1929 | disable_lnk(ch); |
| 1930 | |
| 1931 | if (!OMAP_DMA_CHAIN_QEMPTY(chain_id)) |
| 1932 | OMAP_DMA_CHAIN_INCQHEAD(chain_id); |
| 1933 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1934 | status = p->dma_read(CSR, ch); |
Adrian Hunter | 4fb699b | 2010-11-24 13:23:21 +0200 | [diff] [blame] | 1935 | p->dma_write(status, CSR, ch); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1936 | } |
| 1937 | |
Jarkko Nikula | 538528d | 2008-02-13 11:47:29 +0200 | [diff] [blame] | 1938 | if (likely(dma_chan[ch].callback != NULL)) |
| 1939 | dma_chan[ch].callback(ch, status, dma_chan[ch].data); |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 1940 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1941 | return 0; |
| 1942 | } |
| 1943 | |
| 1944 | /* STATUS register count is from 1-32 while our is 0-31 */ |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 1945 | static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1946 | { |
Santosh Shilimkar | 52176e7 | 2009-03-23 18:07:49 -0700 | [diff] [blame] | 1947 | u32 val, enable_reg; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1948 | int i; |
| 1949 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1950 | val = p->dma_read(IRQSTATUS_L0, 0); |
Juha Yrjola | 3151369 | 2006-12-06 17:13:47 -0800 | [diff] [blame] | 1951 | if (val == 0) { |
| 1952 | if (printk_ratelimit()) |
| 1953 | printk(KERN_WARNING "Spurious DMA IRQ\n"); |
| 1954 | return IRQ_HANDLED; |
| 1955 | } |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1956 | enable_reg = p->dma_read(IRQENABLE_L0, 0); |
Santosh Shilimkar | 52176e7 | 2009-03-23 18:07:49 -0700 | [diff] [blame] | 1957 | val &= enable_reg; /* Dispatch only relevant interrupts */ |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 1958 | for (i = 0; i < dma_lch_count && val != 0; i++) { |
Juha Yrjola | 3151369 | 2006-12-06 17:13:47 -0800 | [diff] [blame] | 1959 | if (val & 1) |
| 1960 | omap2_dma_handle_ch(i); |
| 1961 | val >>= 1; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | return IRQ_HANDLED; |
| 1965 | } |
| 1966 | |
| 1967 | static struct irqaction omap24xx_dma_irq = { |
| 1968 | .name = "DMA", |
| 1969 | .handler = omap2_dma_irq_handler, |
Thomas Gleixner | 52e405e | 2006-07-03 02:20:05 +0200 | [diff] [blame] | 1970 | .flags = IRQF_DISABLED |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1971 | }; |
| 1972 | |
| 1973 | #else |
| 1974 | static struct irqaction omap24xx_dma_irq; |
| 1975 | #endif |
| 1976 | |
| 1977 | /*----------------------------------------------------------------------------*/ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1978 | |
Tero Kristo | f2d1185 | 2008-08-28 13:13:31 +0000 | [diff] [blame] | 1979 | void omap_dma_global_context_save(void) |
| 1980 | { |
| 1981 | omap_dma_global_context.dma_irqenable_l0 = |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1982 | p->dma_read(IRQENABLE_L0, 0); |
Tero Kristo | f2d1185 | 2008-08-28 13:13:31 +0000 | [diff] [blame] | 1983 | omap_dma_global_context.dma_ocp_sysconfig = |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1984 | p->dma_read(OCP_SYSCONFIG, 0); |
| 1985 | omap_dma_global_context.dma_gcr = p->dma_read(GCR, 0); |
Tero Kristo | f2d1185 | 2008-08-28 13:13:31 +0000 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | void omap_dma_global_context_restore(void) |
| 1989 | { |
Aaro Koskinen | bf07c9f | 2009-05-20 16:58:30 +0300 | [diff] [blame] | 1990 | int ch; |
| 1991 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1992 | p->dma_write(omap_dma_global_context.dma_gcr, GCR, 0); |
| 1993 | p->dma_write(omap_dma_global_context.dma_ocp_sysconfig, |
G, Manjunath Kondaiah | a4c537c7 | 2010-12-20 18:27:17 -0800 | [diff] [blame] | 1994 | OCP_SYSCONFIG, 0); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1995 | p->dma_write(omap_dma_global_context.dma_irqenable_l0, |
G, Manjunath Kondaiah | a4c537c7 | 2010-12-20 18:27:17 -0800 | [diff] [blame] | 1996 | IRQENABLE_L0, 0); |
Tero Kristo | f2d1185 | 2008-08-28 13:13:31 +0000 | [diff] [blame] | 1997 | |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 1998 | if (IS_DMA_ERRATA(DMA_ROMCODE_BUG)) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 1999 | p->dma_write(0x3 , IRQSTATUS_L0, 0); |
Aaro Koskinen | bf07c9f | 2009-05-20 16:58:30 +0300 | [diff] [blame] | 2000 | |
| 2001 | for (ch = 0; ch < dma_chan_count; ch++) |
| 2002 | if (dma_chan[ch].dev_id != -1) |
| 2003 | omap_clear_dma(ch); |
Tero Kristo | f2d1185 | 2008-08-28 13:13:31 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2006 | static int __devinit omap_system_dma_probe(struct platform_device *pdev) |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 2007 | { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2008 | int ch, ret = 0; |
| 2009 | int dma_irq; |
| 2010 | char irq_name[4]; |
| 2011 | int irq_rel; |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 2012 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2013 | p = pdev->dev.platform_data; |
| 2014 | if (!p) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 2015 | dev_err(&pdev->dev, |
| 2016 | "%s: System DMA initialized without platform data\n", |
| 2017 | __func__); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2018 | return -EINVAL; |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 2019 | } |
| 2020 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2021 | d = p->dma_attr; |
| 2022 | errata = p->errata; |
G, Manjunath Kondaiah | d3c9be2 | 2010-12-20 18:27:18 -0800 | [diff] [blame] | 2023 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2024 | if ((d->dev_caps & RESERVE_CHANNEL) && omap_dma_reserve_channels |
Santosh Shilimkar | 2263f02 | 2009-03-23 18:07:48 -0700 | [diff] [blame] | 2025 | && (omap_dma_reserve_channels <= dma_lch_count)) |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2026 | d->lch_count = omap_dma_reserve_channels; |
Santosh Shilimkar | 2263f02 | 2009-03-23 18:07:48 -0700 | [diff] [blame] | 2027 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2028 | dma_lch_count = d->lch_count; |
| 2029 | dma_chan_count = dma_lch_count; |
| 2030 | dma_chan = d->chan; |
| 2031 | enable_1510_mode = d->dev_caps & ENABLE_1510_MODE; |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 2032 | |
| 2033 | if (cpu_class_is_omap2()) { |
| 2034 | dma_linked_lch = kzalloc(sizeof(struct dma_link_info) * |
| 2035 | dma_lch_count, GFP_KERNEL); |
| 2036 | if (!dma_linked_lch) { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2037 | ret = -ENOMEM; |
| 2038 | goto exit_dma_lch_fail; |
Tony Lindgren | 4d96372 | 2008-07-03 12:24:31 +0300 | [diff] [blame] | 2039 | } |
| 2040 | } |
| 2041 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2042 | spin_lock_init(&dma_chan_lock); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2043 | for (ch = 0; ch < dma_chan_count; ch++) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 2044 | omap_clear_dma(ch); |
Mika Westerberg | ada8d4a | 2010-05-14 12:05:25 -0700 | [diff] [blame] | 2045 | if (cpu_class_is_omap2()) |
| 2046 | omap2_disable_irq_lch(ch); |
| 2047 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2048 | dma_chan[ch].dev_id = -1; |
| 2049 | dma_chan[ch].next_lch = -1; |
| 2050 | |
| 2051 | if (ch >= 6 && enable_1510_mode) |
| 2052 | continue; |
| 2053 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 2054 | if (cpu_class_is_omap1()) { |
Tony Lindgren | 97b7f71 | 2008-07-03 12:24:37 +0300 | [diff] [blame] | 2055 | /* |
| 2056 | * request_irq() doesn't like dev_id (ie. ch) being |
| 2057 | * zero, so we have to kludge around this. |
| 2058 | */ |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2059 | sprintf(&irq_name[0], "%d", ch); |
| 2060 | dma_irq = platform_get_irq_byname(pdev, irq_name); |
| 2061 | |
| 2062 | if (dma_irq < 0) { |
| 2063 | ret = dma_irq; |
| 2064 | goto exit_dma_irq_fail; |
| 2065 | } |
| 2066 | |
| 2067 | /* INT_DMA_LCD is handled in lcd_dma.c */ |
| 2068 | if (dma_irq == INT_DMA_LCD) |
| 2069 | continue; |
| 2070 | |
| 2071 | ret = request_irq(dma_irq, |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 2072 | omap1_dma_irq_handler, 0, "DMA", |
| 2073 | (void *) (ch + 1)); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2074 | if (ret != 0) |
| 2075 | goto exit_dma_irq_fail; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 2076 | } |
| 2077 | } |
| 2078 | |
Santosh Shilimkar | d07c3df | 2012-04-28 20:19:10 +0530 | [diff] [blame] | 2079 | if (cpu_class_is_omap2() && !cpu_is_omap242x()) |
Anand Gadiyar | f8151e5 | 2007-12-01 12:14:11 -0800 | [diff] [blame] | 2080 | omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE, |
| 2081 | DMA_DEFAULT_FIFO_DEPTH, 0); |
| 2082 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 2083 | if (cpu_class_is_omap2()) { |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2084 | strcpy(irq_name, "0"); |
| 2085 | dma_irq = platform_get_irq_byname(pdev, irq_name); |
| 2086 | if (dma_irq < 0) { |
| 2087 | dev_err(&pdev->dev, "failed: request IRQ %d", dma_irq); |
| 2088 | goto exit_dma_lch_fail; |
| 2089 | } |
| 2090 | ret = setup_irq(dma_irq, &omap24xx_dma_irq); |
| 2091 | if (ret) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 2092 | dev_err(&pdev->dev, "set_up failed for IRQ %d for DMA (error %d)\n", |
| 2093 | dma_irq, ret); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2094 | goto exit_dma_lch_fail; |
Kalle Jokiniemi | ba50ea7 | 2009-03-26 15:59:00 +0200 | [diff] [blame] | 2095 | } |
Kalle Jokiniemi | aecedb9 | 2009-06-23 13:30:24 +0300 | [diff] [blame] | 2096 | } |
| 2097 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2098 | /* reserve dma channels 0 and 1 in high security devices */ |
| 2099 | if (cpu_is_omap34xx() && |
| 2100 | (omap_type() != OMAP2_DEVICE_TYPE_GP)) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 2101 | pr_info("Reserving DMA channels 0 and 1 for HS ROM code\n"); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2102 | dma_chan[0].dev_id = 0; |
| 2103 | dma_chan[1].dev_id = 1; |
| 2104 | } |
| 2105 | p->show_dma_caps(); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2106 | return 0; |
Tony Lindgren | 7e9bf84 | 2009-10-19 15:25:15 -0700 | [diff] [blame] | 2107 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2108 | exit_dma_irq_fail: |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 2109 | dev_err(&pdev->dev, "unable to request IRQ %d for DMA (error %d)\n", |
| 2110 | dma_irq, ret); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2111 | for (irq_rel = 0; irq_rel < ch; irq_rel++) { |
| 2112 | dma_irq = platform_get_irq(pdev, irq_rel); |
| 2113 | free_irq(dma_irq, (void *)(irq_rel + 1)); |
| 2114 | } |
| 2115 | |
| 2116 | exit_dma_lch_fail: |
| 2117 | kfree(p); |
| 2118 | kfree(d); |
Tony Lindgren | 7e9bf84 | 2009-10-19 15:25:15 -0700 | [diff] [blame] | 2119 | kfree(dma_chan); |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2120 | return ret; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2121 | } |
| 2122 | |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2123 | static int __devexit omap_system_dma_remove(struct platform_device *pdev) |
| 2124 | { |
| 2125 | int dma_irq; |
| 2126 | |
| 2127 | if (cpu_class_is_omap2()) { |
| 2128 | char irq_name[4]; |
| 2129 | strcpy(irq_name, "0"); |
| 2130 | dma_irq = platform_get_irq_byname(pdev, irq_name); |
| 2131 | remove_irq(dma_irq, &omap24xx_dma_irq); |
| 2132 | } else { |
| 2133 | int irq_rel = 0; |
| 2134 | for ( ; irq_rel < dma_chan_count; irq_rel++) { |
| 2135 | dma_irq = platform_get_irq(pdev, irq_rel); |
| 2136 | free_irq(dma_irq, (void *)(irq_rel + 1)); |
| 2137 | } |
| 2138 | } |
| 2139 | kfree(p); |
| 2140 | kfree(d); |
| 2141 | kfree(dma_chan); |
| 2142 | return 0; |
| 2143 | } |
| 2144 | |
| 2145 | static struct platform_driver omap_system_dma_driver = { |
| 2146 | .probe = omap_system_dma_probe, |
Tony Lindgren | 3e2e613 | 2012-02-23 14:58:08 -0800 | [diff] [blame] | 2147 | .remove = __devexit_p(omap_system_dma_remove), |
G, Manjunath Kondaiah | f31cc96 | 2010-12-20 18:27:19 -0800 | [diff] [blame] | 2148 | .driver = { |
| 2149 | .name = "omap_dma_system" |
| 2150 | }, |
| 2151 | }; |
| 2152 | |
| 2153 | static int __init omap_system_dma_init(void) |
| 2154 | { |
| 2155 | return platform_driver_register(&omap_system_dma_driver); |
| 2156 | } |
| 2157 | arch_initcall(omap_system_dma_init); |
| 2158 | |
| 2159 | static void __exit omap_system_dma_exit(void) |
| 2160 | { |
| 2161 | platform_driver_unregister(&omap_system_dma_driver); |
| 2162 | } |
| 2163 | |
| 2164 | MODULE_DESCRIPTION("OMAP SYSTEM DMA DRIVER"); |
| 2165 | MODULE_LICENSE("GPL"); |
| 2166 | MODULE_ALIAS("platform:" DRIVER_NAME); |
| 2167 | MODULE_AUTHOR("Texas Instruments Inc"); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2168 | |
Santosh Shilimkar | 2263f02 | 2009-03-23 18:07:48 -0700 | [diff] [blame] | 2169 | /* |
| 2170 | * Reserve the omap SDMA channels using cmdline bootarg |
| 2171 | * "omap_dma_reserve_ch=". The valid range is 1 to 32 |
| 2172 | */ |
| 2173 | static int __init omap_dma_cmdline_reserve_ch(char *str) |
| 2174 | { |
| 2175 | if (get_option(&str, &omap_dma_reserve_channels) != 1) |
| 2176 | omap_dma_reserve_channels = 0; |
| 2177 | return 1; |
| 2178 | } |
| 2179 | |
| 2180 | __setup("omap_dma_reserve_ch=", omap_dma_cmdline_reserve_ch); |
| 2181 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2182 | |