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