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