Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Synopsys DesignWare DMA Controller (aka DMACA on |
| 3 | * AVR32 systems.) |
| 4 | * |
| 5 | * Copyright (C) 2007-2008 Atmel Corporation |
Viresh Kumar | aecb7b6 | 2011-05-24 14:04:09 +0530 | [diff] [blame] | 6 | * Copyright (C) 2010-2011 ST Microelectronics |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 12 | #include <linux/bitops.h> |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 13 | #include <linux/clk.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/dmaengine.h> |
| 16 | #include <linux/dma-mapping.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/io.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/slab.h> |
| 24 | |
| 25 | #include "dw_dmac_regs.h" |
Russell King - ARM Linux | d2ebfb3 | 2012-03-06 22:34:26 +0000 | [diff] [blame^] | 26 | #include "dmaengine.h" |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * This supports the Synopsys "DesignWare AHB Central DMA Controller", |
| 30 | * (DW_ahb_dmac) which is used with various AMBA 2.0 systems (not all |
| 31 | * of which use ARM any more). See the "Databook" from Synopsys for |
| 32 | * information beyond what licensees probably provide. |
| 33 | * |
| 34 | * The driver has currently been tested only with the Atmel AT32AP7000, |
| 35 | * which does not support descriptor writeback. |
| 36 | */ |
| 37 | |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 38 | #define DWC_DEFAULT_CTLLO(_chan) ({ \ |
| 39 | struct dw_dma_slave *__slave = (_chan->private); \ |
| 40 | struct dw_dma_chan *_dwc = to_dw_dma_chan(_chan); \ |
| 41 | struct dma_slave_config *_sconfig = &_dwc->dma_sconfig; \ |
| 42 | int _dms = __slave ? __slave->dst_master : 0; \ |
| 43 | int _sms = __slave ? __slave->src_master : 1; \ |
| 44 | u8 _smsize = __slave ? _sconfig->src_maxburst : \ |
| 45 | DW_DMA_MSIZE_16; \ |
| 46 | u8 _dmsize = __slave ? _sconfig->dst_maxburst : \ |
| 47 | DW_DMA_MSIZE_16; \ |
Jamie Iles | f301c06 | 2011-01-21 14:11:53 +0000 | [diff] [blame] | 48 | \ |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 49 | (DWC_CTLL_DST_MSIZE(_dmsize) \ |
| 50 | | DWC_CTLL_SRC_MSIZE(_smsize) \ |
Jamie Iles | f301c06 | 2011-01-21 14:11:53 +0000 | [diff] [blame] | 51 | | DWC_CTLL_LLP_D_EN \ |
| 52 | | DWC_CTLL_LLP_S_EN \ |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 53 | | DWC_CTLL_DMS(_dms) \ |
| 54 | | DWC_CTLL_SMS(_sms)); \ |
Jamie Iles | f301c06 | 2011-01-21 14:11:53 +0000 | [diff] [blame] | 55 | }) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * This is configuration-dependent and usually a funny size like 4095. |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 59 | * |
| 60 | * Note that this is a transfer count, i.e. if we transfer 32-bit |
Viresh Kumar | 418e740 | 2011-03-04 15:42:50 +0530 | [diff] [blame] | 61 | * words, we can do 16380 bytes per descriptor. |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 62 | * |
| 63 | * This parameter is also system-specific. |
| 64 | */ |
Viresh Kumar | 418e740 | 2011-03-04 15:42:50 +0530 | [diff] [blame] | 65 | #define DWC_MAX_COUNT 4095U |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * Number of descriptors to allocate for each channel. This should be |
| 69 | * made configurable somehow; preferably, the clients (at least the |
| 70 | * ones using slave transfers) should be able to give us a hint. |
| 71 | */ |
| 72 | #define NR_DESCS_PER_CHANNEL 64 |
| 73 | |
| 74 | /*----------------------------------------------------------------------*/ |
| 75 | |
| 76 | /* |
| 77 | * Because we're not relying on writeback from the controller (it may not |
| 78 | * even be configured into the core!) we don't need to use dma_pool. These |
| 79 | * descriptors -- and associated data -- are cacheable. We do need to make |
| 80 | * sure their dcache entries are written back before handing them off to |
| 81 | * the controller, though. |
| 82 | */ |
| 83 | |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 84 | static struct device *chan2dev(struct dma_chan *chan) |
| 85 | { |
| 86 | return &chan->dev->device; |
| 87 | } |
| 88 | static struct device *chan2parent(struct dma_chan *chan) |
| 89 | { |
| 90 | return chan->dev->device.parent; |
| 91 | } |
| 92 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 93 | static struct dw_desc *dwc_first_active(struct dw_dma_chan *dwc) |
| 94 | { |
| 95 | return list_entry(dwc->active_list.next, struct dw_desc, desc_node); |
| 96 | } |
| 97 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 98 | static struct dw_desc *dwc_desc_get(struct dw_dma_chan *dwc) |
| 99 | { |
| 100 | struct dw_desc *desc, *_desc; |
| 101 | struct dw_desc *ret = NULL; |
| 102 | unsigned int i = 0; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 103 | unsigned long flags; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 104 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 105 | spin_lock_irqsave(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 106 | list_for_each_entry_safe(desc, _desc, &dwc->free_list, desc_node) { |
| 107 | if (async_tx_test_ack(&desc->txd)) { |
| 108 | list_del(&desc->desc_node); |
| 109 | ret = desc; |
| 110 | break; |
| 111 | } |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 112 | dev_dbg(chan2dev(&dwc->chan), "desc %p not ACKed\n", desc); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 113 | i++; |
| 114 | } |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 115 | spin_unlock_irqrestore(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 116 | |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 117 | dev_vdbg(chan2dev(&dwc->chan), "scanned %u descriptors on freelist\n", i); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 118 | |
| 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | static void dwc_sync_desc_for_cpu(struct dw_dma_chan *dwc, struct dw_desc *desc) |
| 123 | { |
| 124 | struct dw_desc *child; |
| 125 | |
Dan Williams | e0bd0f8 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 126 | list_for_each_entry(child, &desc->tx_list, desc_node) |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 127 | dma_sync_single_for_cpu(chan2parent(&dwc->chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 128 | child->txd.phys, sizeof(child->lli), |
| 129 | DMA_TO_DEVICE); |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 130 | dma_sync_single_for_cpu(chan2parent(&dwc->chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 131 | desc->txd.phys, sizeof(desc->lli), |
| 132 | DMA_TO_DEVICE); |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Move a descriptor, including any children, to the free list. |
| 137 | * `desc' must not be on any lists. |
| 138 | */ |
| 139 | static void dwc_desc_put(struct dw_dma_chan *dwc, struct dw_desc *desc) |
| 140 | { |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 141 | unsigned long flags; |
| 142 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 143 | if (desc) { |
| 144 | struct dw_desc *child; |
| 145 | |
| 146 | dwc_sync_desc_for_cpu(dwc, desc); |
| 147 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 148 | spin_lock_irqsave(&dwc->lock, flags); |
Dan Williams | e0bd0f8 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 149 | list_for_each_entry(child, &desc->tx_list, desc_node) |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 150 | dev_vdbg(chan2dev(&dwc->chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 151 | "moving child desc %p to freelist\n", |
| 152 | child); |
Dan Williams | e0bd0f8 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 153 | list_splice_init(&desc->tx_list, &dwc->free_list); |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 154 | dev_vdbg(chan2dev(&dwc->chan), "moving desc %p to freelist\n", desc); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 155 | list_add(&desc->desc_node, &dwc->free_list); |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 156 | spin_unlock_irqrestore(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
| 160 | /* Called with dwc->lock held and bh disabled */ |
| 161 | static dma_cookie_t |
| 162 | dwc_assign_cookie(struct dw_dma_chan *dwc, struct dw_desc *desc) |
| 163 | { |
| 164 | dma_cookie_t cookie = dwc->chan.cookie; |
| 165 | |
| 166 | if (++cookie < 0) |
| 167 | cookie = 1; |
| 168 | |
| 169 | dwc->chan.cookie = cookie; |
| 170 | desc->txd.cookie = cookie; |
| 171 | |
| 172 | return cookie; |
| 173 | } |
| 174 | |
Viresh Kumar | 61e183f | 2011-11-17 16:01:29 +0530 | [diff] [blame] | 175 | static void dwc_initialize(struct dw_dma_chan *dwc) |
| 176 | { |
| 177 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); |
| 178 | struct dw_dma_slave *dws = dwc->chan.private; |
| 179 | u32 cfghi = DWC_CFGH_FIFO_MODE; |
| 180 | u32 cfglo = DWC_CFGL_CH_PRIOR(dwc->priority); |
| 181 | |
| 182 | if (dwc->initialized == true) |
| 183 | return; |
| 184 | |
| 185 | if (dws) { |
| 186 | /* |
| 187 | * We need controller-specific data to set up slave |
| 188 | * transfers. |
| 189 | */ |
| 190 | BUG_ON(!dws->dma_dev || dws->dma_dev != dw->dma.dev); |
| 191 | |
| 192 | cfghi = dws->cfg_hi; |
| 193 | cfglo |= dws->cfg_lo & ~DWC_CFGL_CH_PRIOR_MASK; |
| 194 | } |
| 195 | |
| 196 | channel_writel(dwc, CFG_LO, cfglo); |
| 197 | channel_writel(dwc, CFG_HI, cfghi); |
| 198 | |
| 199 | /* Enable interrupts */ |
| 200 | channel_set_bit(dw, MASK.XFER, dwc->mask); |
Viresh Kumar | 61e183f | 2011-11-17 16:01:29 +0530 | [diff] [blame] | 201 | channel_set_bit(dw, MASK.ERROR, dwc->mask); |
| 202 | |
| 203 | dwc->initialized = true; |
| 204 | } |
| 205 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 206 | /*----------------------------------------------------------------------*/ |
| 207 | |
| 208 | /* Called with dwc->lock held and bh disabled */ |
| 209 | static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first) |
| 210 | { |
| 211 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); |
| 212 | |
| 213 | /* ASSERT: channel is idle */ |
| 214 | if (dma_readl(dw, CH_EN) & dwc->mask) { |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 215 | dev_err(chan2dev(&dwc->chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 216 | "BUG: Attempted to start non-idle channel\n"); |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 217 | dev_err(chan2dev(&dwc->chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 218 | " SAR: 0x%x DAR: 0x%x LLP: 0x%x CTL: 0x%x:%08x\n", |
| 219 | channel_readl(dwc, SAR), |
| 220 | channel_readl(dwc, DAR), |
| 221 | channel_readl(dwc, LLP), |
| 222 | channel_readl(dwc, CTL_HI), |
| 223 | channel_readl(dwc, CTL_LO)); |
| 224 | |
| 225 | /* The tasklet will hopefully advance the queue... */ |
| 226 | return; |
| 227 | } |
| 228 | |
Viresh Kumar | 61e183f | 2011-11-17 16:01:29 +0530 | [diff] [blame] | 229 | dwc_initialize(dwc); |
| 230 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 231 | channel_writel(dwc, LLP, first->txd.phys); |
| 232 | channel_writel(dwc, CTL_LO, |
| 233 | DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN); |
| 234 | channel_writel(dwc, CTL_HI, 0); |
| 235 | channel_set_bit(dw, CH_EN, dwc->mask); |
| 236 | } |
| 237 | |
| 238 | /*----------------------------------------------------------------------*/ |
| 239 | |
| 240 | static void |
Viresh Kumar | 5fedefb | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 241 | dwc_descriptor_complete(struct dw_dma_chan *dwc, struct dw_desc *desc, |
| 242 | bool callback_required) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 243 | { |
Viresh Kumar | 5fedefb | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 244 | dma_async_tx_callback callback = NULL; |
| 245 | void *param = NULL; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 246 | struct dma_async_tx_descriptor *txd = &desc->txd; |
Viresh Kumar | e518076 | 2011-03-03 15:47:20 +0530 | [diff] [blame] | 247 | struct dw_desc *child; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 248 | unsigned long flags; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 249 | |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 250 | dev_vdbg(chan2dev(&dwc->chan), "descriptor %u complete\n", txd->cookie); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 251 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 252 | spin_lock_irqsave(&dwc->lock, flags); |
Russell King - ARM Linux | 4d4e58d | 2012-03-06 22:34:06 +0000 | [diff] [blame] | 253 | dwc->chan.completed_cookie = txd->cookie; |
Viresh Kumar | 5fedefb | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 254 | if (callback_required) { |
| 255 | callback = txd->callback; |
| 256 | param = txd->callback_param; |
| 257 | } |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 258 | |
| 259 | dwc_sync_desc_for_cpu(dwc, desc); |
Viresh Kumar | e518076 | 2011-03-03 15:47:20 +0530 | [diff] [blame] | 260 | |
| 261 | /* async_tx_ack */ |
| 262 | list_for_each_entry(child, &desc->tx_list, desc_node) |
| 263 | async_tx_ack(&child->txd); |
| 264 | async_tx_ack(&desc->txd); |
| 265 | |
Dan Williams | e0bd0f8 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 266 | list_splice_init(&desc->tx_list, &dwc->free_list); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 267 | list_move(&desc->desc_node, &dwc->free_list); |
| 268 | |
Atsushi Nemoto | 657a77f | 2009-09-08 17:53:05 -0700 | [diff] [blame] | 269 | if (!dwc->chan.private) { |
| 270 | struct device *parent = chan2parent(&dwc->chan); |
| 271 | if (!(txd->flags & DMA_COMPL_SKIP_DEST_UNMAP)) { |
| 272 | if (txd->flags & DMA_COMPL_DEST_UNMAP_SINGLE) |
| 273 | dma_unmap_single(parent, desc->lli.dar, |
| 274 | desc->len, DMA_FROM_DEVICE); |
| 275 | else |
| 276 | dma_unmap_page(parent, desc->lli.dar, |
| 277 | desc->len, DMA_FROM_DEVICE); |
| 278 | } |
| 279 | if (!(txd->flags & DMA_COMPL_SKIP_SRC_UNMAP)) { |
| 280 | if (txd->flags & DMA_COMPL_SRC_UNMAP_SINGLE) |
| 281 | dma_unmap_single(parent, desc->lli.sar, |
| 282 | desc->len, DMA_TO_DEVICE); |
| 283 | else |
| 284 | dma_unmap_page(parent, desc->lli.sar, |
| 285 | desc->len, DMA_TO_DEVICE); |
| 286 | } |
| 287 | } |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 288 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 289 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 290 | |
Viresh Kumar | 5fedefb | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 291 | if (callback_required && callback) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 292 | callback(param); |
| 293 | } |
| 294 | |
| 295 | static void dwc_complete_all(struct dw_dma *dw, struct dw_dma_chan *dwc) |
| 296 | { |
| 297 | struct dw_desc *desc, *_desc; |
| 298 | LIST_HEAD(list); |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 299 | unsigned long flags; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 300 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 301 | spin_lock_irqsave(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 302 | if (dma_readl(dw, CH_EN) & dwc->mask) { |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 303 | dev_err(chan2dev(&dwc->chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 304 | "BUG: XFER bit set, but channel not idle!\n"); |
| 305 | |
| 306 | /* Try to continue after resetting the channel... */ |
| 307 | channel_clear_bit(dw, CH_EN, dwc->mask); |
| 308 | while (dma_readl(dw, CH_EN) & dwc->mask) |
| 309 | cpu_relax(); |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | * Submit queued descriptors ASAP, i.e. before we go through |
| 314 | * the completed ones. |
| 315 | */ |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 316 | list_splice_init(&dwc->active_list, &list); |
Viresh Kumar | f336e42 | 2011-03-03 15:47:16 +0530 | [diff] [blame] | 317 | if (!list_empty(&dwc->queue)) { |
| 318 | list_move(dwc->queue.next, &dwc->active_list); |
| 319 | dwc_dostart(dwc, dwc_first_active(dwc)); |
| 320 | } |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 321 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 322 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 323 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 324 | list_for_each_entry_safe(desc, _desc, &list, desc_node) |
Viresh Kumar | 5fedefb | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 325 | dwc_descriptor_complete(dwc, desc, true); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc) |
| 329 | { |
| 330 | dma_addr_t llp; |
| 331 | struct dw_desc *desc, *_desc; |
| 332 | struct dw_desc *child; |
| 333 | u32 status_xfer; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 334 | unsigned long flags; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 335 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 336 | spin_lock_irqsave(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 337 | llp = channel_readl(dwc, LLP); |
| 338 | status_xfer = dma_readl(dw, RAW.XFER); |
| 339 | |
| 340 | if (status_xfer & dwc->mask) { |
| 341 | /* Everything we've submitted is done */ |
| 342 | dma_writel(dw, CLEAR.XFER, dwc->mask); |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 343 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 344 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 345 | dwc_complete_all(dw, dwc); |
| 346 | return; |
| 347 | } |
| 348 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 349 | if (list_empty(&dwc->active_list)) { |
| 350 | spin_unlock_irqrestore(&dwc->lock, flags); |
Jamie Iles | 087809f | 2011-01-21 14:11:52 +0000 | [diff] [blame] | 351 | return; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 352 | } |
Jamie Iles | 087809f | 2011-01-21 14:11:52 +0000 | [diff] [blame] | 353 | |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 354 | dev_vdbg(chan2dev(&dwc->chan), "scan_descriptors: llp=0x%x\n", llp); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 355 | |
| 356 | list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) { |
Viresh Kumar | 84adccf | 2011-03-24 11:32:15 +0530 | [diff] [blame] | 357 | /* check first descriptors addr */ |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 358 | if (desc->txd.phys == llp) { |
| 359 | spin_unlock_irqrestore(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 360 | return; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 361 | } |
Viresh Kumar | 84adccf | 2011-03-24 11:32:15 +0530 | [diff] [blame] | 362 | |
| 363 | /* check first descriptors llp */ |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 364 | if (desc->lli.llp == llp) { |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 365 | /* This one is currently in progress */ |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 366 | spin_unlock_irqrestore(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 367 | return; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 368 | } |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 369 | |
Dan Williams | e0bd0f8 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 370 | list_for_each_entry(child, &desc->tx_list, desc_node) |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 371 | if (child->lli.llp == llp) { |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 372 | /* Currently in progress */ |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 373 | spin_unlock_irqrestore(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 374 | return; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 375 | } |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 376 | |
| 377 | /* |
| 378 | * No descriptors so far seem to be in progress, i.e. |
| 379 | * this one must be done. |
| 380 | */ |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 381 | spin_unlock_irqrestore(&dwc->lock, flags); |
Viresh Kumar | 5fedefb | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 382 | dwc_descriptor_complete(dwc, desc, true); |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 383 | spin_lock_irqsave(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 386 | dev_err(chan2dev(&dwc->chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 387 | "BUG: All descriptors done, but channel not idle!\n"); |
| 388 | |
| 389 | /* Try to continue after resetting the channel... */ |
| 390 | channel_clear_bit(dw, CH_EN, dwc->mask); |
| 391 | while (dma_readl(dw, CH_EN) & dwc->mask) |
| 392 | cpu_relax(); |
| 393 | |
| 394 | if (!list_empty(&dwc->queue)) { |
Viresh Kumar | f336e42 | 2011-03-03 15:47:16 +0530 | [diff] [blame] | 395 | list_move(dwc->queue.next, &dwc->active_list); |
| 396 | dwc_dostart(dwc, dwc_first_active(dwc)); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 397 | } |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 398 | spin_unlock_irqrestore(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | static void dwc_dump_lli(struct dw_dma_chan *dwc, struct dw_lli *lli) |
| 402 | { |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 403 | dev_printk(KERN_CRIT, chan2dev(&dwc->chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 404 | " desc: s0x%x d0x%x l0x%x c0x%x:%x\n", |
| 405 | lli->sar, lli->dar, lli->llp, |
| 406 | lli->ctlhi, lli->ctllo); |
| 407 | } |
| 408 | |
| 409 | static void dwc_handle_error(struct dw_dma *dw, struct dw_dma_chan *dwc) |
| 410 | { |
| 411 | struct dw_desc *bad_desc; |
| 412 | struct dw_desc *child; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 413 | unsigned long flags; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 414 | |
| 415 | dwc_scan_descriptors(dw, dwc); |
| 416 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 417 | spin_lock_irqsave(&dwc->lock, flags); |
| 418 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 419 | /* |
| 420 | * The descriptor currently at the head of the active list is |
| 421 | * borked. Since we don't have any way to report errors, we'll |
| 422 | * just have to scream loudly and try to carry on. |
| 423 | */ |
| 424 | bad_desc = dwc_first_active(dwc); |
| 425 | list_del_init(&bad_desc->desc_node); |
Viresh Kumar | f336e42 | 2011-03-03 15:47:16 +0530 | [diff] [blame] | 426 | list_move(dwc->queue.next, dwc->active_list.prev); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 427 | |
| 428 | /* Clear the error flag and try to restart the controller */ |
| 429 | dma_writel(dw, CLEAR.ERROR, dwc->mask); |
| 430 | if (!list_empty(&dwc->active_list)) |
| 431 | dwc_dostart(dwc, dwc_first_active(dwc)); |
| 432 | |
| 433 | /* |
| 434 | * KERN_CRITICAL may seem harsh, but since this only happens |
| 435 | * when someone submits a bad physical address in a |
| 436 | * descriptor, we should consider ourselves lucky that the |
| 437 | * controller flagged an error instead of scribbling over |
| 438 | * random memory locations. |
| 439 | */ |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 440 | dev_printk(KERN_CRIT, chan2dev(&dwc->chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 441 | "Bad descriptor submitted for DMA!\n"); |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 442 | dev_printk(KERN_CRIT, chan2dev(&dwc->chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 443 | " cookie: %d\n", bad_desc->txd.cookie); |
| 444 | dwc_dump_lli(dwc, &bad_desc->lli); |
Dan Williams | e0bd0f8 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 445 | list_for_each_entry(child, &bad_desc->tx_list, desc_node) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 446 | dwc_dump_lli(dwc, &child->lli); |
| 447 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 448 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 449 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 450 | /* Pretend the descriptor completed successfully */ |
Viresh Kumar | 5fedefb | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 451 | dwc_descriptor_complete(dwc, bad_desc, true); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 454 | /* --------------------- Cyclic DMA API extensions -------------------- */ |
| 455 | |
| 456 | inline dma_addr_t dw_dma_get_src_addr(struct dma_chan *chan) |
| 457 | { |
| 458 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 459 | return channel_readl(dwc, SAR); |
| 460 | } |
| 461 | EXPORT_SYMBOL(dw_dma_get_src_addr); |
| 462 | |
| 463 | inline dma_addr_t dw_dma_get_dst_addr(struct dma_chan *chan) |
| 464 | { |
| 465 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 466 | return channel_readl(dwc, DAR); |
| 467 | } |
| 468 | EXPORT_SYMBOL(dw_dma_get_dst_addr); |
| 469 | |
| 470 | /* called with dwc->lock held and all DMAC interrupts disabled */ |
| 471 | static void dwc_handle_cyclic(struct dw_dma *dw, struct dw_dma_chan *dwc, |
Viresh Kumar | ff7b05f | 2012-02-01 16:12:23 +0530 | [diff] [blame] | 472 | u32 status_err, u32 status_xfer) |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 473 | { |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 474 | unsigned long flags; |
| 475 | |
Viresh Kumar | ff7b05f | 2012-02-01 16:12:23 +0530 | [diff] [blame] | 476 | if (dwc->mask) { |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 477 | void (*callback)(void *param); |
| 478 | void *callback_param; |
| 479 | |
| 480 | dev_vdbg(chan2dev(&dwc->chan), "new cyclic period llp 0x%08x\n", |
| 481 | channel_readl(dwc, LLP)); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 482 | |
| 483 | callback = dwc->cdesc->period_callback; |
| 484 | callback_param = dwc->cdesc->period_callback_param; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 485 | |
| 486 | if (callback) |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 487 | callback(callback_param); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /* |
| 491 | * Error and transfer complete are highly unlikely, and will most |
| 492 | * likely be due to a configuration error by the user. |
| 493 | */ |
| 494 | if (unlikely(status_err & dwc->mask) || |
| 495 | unlikely(status_xfer & dwc->mask)) { |
| 496 | int i; |
| 497 | |
| 498 | dev_err(chan2dev(&dwc->chan), "cyclic DMA unexpected %s " |
| 499 | "interrupt, stopping DMA transfer\n", |
| 500 | status_xfer ? "xfer" : "error"); |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 501 | |
| 502 | spin_lock_irqsave(&dwc->lock, flags); |
| 503 | |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 504 | dev_err(chan2dev(&dwc->chan), |
| 505 | " SAR: 0x%x DAR: 0x%x LLP: 0x%x CTL: 0x%x:%08x\n", |
| 506 | channel_readl(dwc, SAR), |
| 507 | channel_readl(dwc, DAR), |
| 508 | channel_readl(dwc, LLP), |
| 509 | channel_readl(dwc, CTL_HI), |
| 510 | channel_readl(dwc, CTL_LO)); |
| 511 | |
| 512 | channel_clear_bit(dw, CH_EN, dwc->mask); |
| 513 | while (dma_readl(dw, CH_EN) & dwc->mask) |
| 514 | cpu_relax(); |
| 515 | |
| 516 | /* make sure DMA does not restart by loading a new list */ |
| 517 | channel_writel(dwc, LLP, 0); |
| 518 | channel_writel(dwc, CTL_LO, 0); |
| 519 | channel_writel(dwc, CTL_HI, 0); |
| 520 | |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 521 | dma_writel(dw, CLEAR.ERROR, dwc->mask); |
| 522 | dma_writel(dw, CLEAR.XFER, dwc->mask); |
| 523 | |
| 524 | for (i = 0; i < dwc->cdesc->periods; i++) |
| 525 | dwc_dump_lli(dwc, &dwc->cdesc->desc[i]->lli); |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 526 | |
| 527 | spin_unlock_irqrestore(&dwc->lock, flags); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | /* ------------------------------------------------------------------------- */ |
| 532 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 533 | static void dw_dma_tasklet(unsigned long data) |
| 534 | { |
| 535 | struct dw_dma *dw = (struct dw_dma *)data; |
| 536 | struct dw_dma_chan *dwc; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 537 | u32 status_xfer; |
| 538 | u32 status_err; |
| 539 | int i; |
| 540 | |
Haavard Skinnemoen | 7fe7b2f | 2008-10-03 15:23:46 -0700 | [diff] [blame] | 541 | status_xfer = dma_readl(dw, RAW.XFER); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 542 | status_err = dma_readl(dw, RAW.ERROR); |
| 543 | |
Viresh Kumar | ff7b05f | 2012-02-01 16:12:23 +0530 | [diff] [blame] | 544 | dev_vdbg(dw->dma.dev, "tasklet: status_err=%x\n", status_err); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 545 | |
| 546 | for (i = 0; i < dw->dma.chancnt; i++) { |
| 547 | dwc = &dw->chan[i]; |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 548 | if (test_bit(DW_DMA_IS_CYCLIC, &dwc->flags)) |
Viresh Kumar | ff7b05f | 2012-02-01 16:12:23 +0530 | [diff] [blame] | 549 | dwc_handle_cyclic(dw, dwc, status_err, status_xfer); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 550 | else if (status_err & (1 << i)) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 551 | dwc_handle_error(dw, dwc); |
Viresh Kumar | ff7b05f | 2012-02-01 16:12:23 +0530 | [diff] [blame] | 552 | else if (status_xfer & (1 << i)) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 553 | dwc_scan_descriptors(dw, dwc); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /* |
Viresh Kumar | ff7b05f | 2012-02-01 16:12:23 +0530 | [diff] [blame] | 557 | * Re-enable interrupts. |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 558 | */ |
| 559 | channel_set_bit(dw, MASK.XFER, dw->all_chan_mask); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 560 | channel_set_bit(dw, MASK.ERROR, dw->all_chan_mask); |
| 561 | } |
| 562 | |
| 563 | static irqreturn_t dw_dma_interrupt(int irq, void *dev_id) |
| 564 | { |
| 565 | struct dw_dma *dw = dev_id; |
| 566 | u32 status; |
| 567 | |
| 568 | dev_vdbg(dw->dma.dev, "interrupt: status=0x%x\n", |
| 569 | dma_readl(dw, STATUS_INT)); |
| 570 | |
| 571 | /* |
| 572 | * Just disable the interrupts. We'll turn them back on in the |
| 573 | * softirq handler. |
| 574 | */ |
| 575 | channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 576 | channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask); |
| 577 | |
| 578 | status = dma_readl(dw, STATUS_INT); |
| 579 | if (status) { |
| 580 | dev_err(dw->dma.dev, |
| 581 | "BUG: Unexpected interrupts pending: 0x%x\n", |
| 582 | status); |
| 583 | |
| 584 | /* Try to recover */ |
| 585 | channel_clear_bit(dw, MASK.XFER, (1 << 8) - 1); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 586 | channel_clear_bit(dw, MASK.SRC_TRAN, (1 << 8) - 1); |
| 587 | channel_clear_bit(dw, MASK.DST_TRAN, (1 << 8) - 1); |
| 588 | channel_clear_bit(dw, MASK.ERROR, (1 << 8) - 1); |
| 589 | } |
| 590 | |
| 591 | tasklet_schedule(&dw->tasklet); |
| 592 | |
| 593 | return IRQ_HANDLED; |
| 594 | } |
| 595 | |
| 596 | /*----------------------------------------------------------------------*/ |
| 597 | |
| 598 | static dma_cookie_t dwc_tx_submit(struct dma_async_tx_descriptor *tx) |
| 599 | { |
| 600 | struct dw_desc *desc = txd_to_dw_desc(tx); |
| 601 | struct dw_dma_chan *dwc = to_dw_dma_chan(tx->chan); |
| 602 | dma_cookie_t cookie; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 603 | unsigned long flags; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 604 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 605 | spin_lock_irqsave(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 606 | cookie = dwc_assign_cookie(dwc, desc); |
| 607 | |
| 608 | /* |
| 609 | * REVISIT: We should attempt to chain as many descriptors as |
| 610 | * possible, perhaps even appending to those already submitted |
| 611 | * for DMA. But this is hard to do in a race-free manner. |
| 612 | */ |
| 613 | if (list_empty(&dwc->active_list)) { |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 614 | dev_vdbg(chan2dev(tx->chan), "tx_submit: started %u\n", |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 615 | desc->txd.cookie); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 616 | list_add_tail(&desc->desc_node, &dwc->active_list); |
Viresh Kumar | f336e42 | 2011-03-03 15:47:16 +0530 | [diff] [blame] | 617 | dwc_dostart(dwc, dwc_first_active(dwc)); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 618 | } else { |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 619 | dev_vdbg(chan2dev(tx->chan), "tx_submit: queued %u\n", |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 620 | desc->txd.cookie); |
| 621 | |
| 622 | list_add_tail(&desc->desc_node, &dwc->queue); |
| 623 | } |
| 624 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 625 | spin_unlock_irqrestore(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 626 | |
| 627 | return cookie; |
| 628 | } |
| 629 | |
| 630 | static struct dma_async_tx_descriptor * |
| 631 | dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, |
| 632 | size_t len, unsigned long flags) |
| 633 | { |
| 634 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 635 | struct dw_desc *desc; |
| 636 | struct dw_desc *first; |
| 637 | struct dw_desc *prev; |
| 638 | size_t xfer_count; |
| 639 | size_t offset; |
| 640 | unsigned int src_width; |
| 641 | unsigned int dst_width; |
| 642 | u32 ctllo; |
| 643 | |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 644 | dev_vdbg(chan2dev(chan), "prep_dma_memcpy d0x%x s0x%x l0x%zx f0x%lx\n", |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 645 | dest, src, len, flags); |
| 646 | |
| 647 | if (unlikely(!len)) { |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 648 | dev_dbg(chan2dev(chan), "prep_dma_memcpy: length is zero!\n"); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 649 | return NULL; |
| 650 | } |
| 651 | |
| 652 | /* |
| 653 | * We can be a lot more clever here, but this should take care |
| 654 | * of the most common optimization. |
| 655 | */ |
Viresh Kumar | a022745 | 2011-03-03 15:47:18 +0530 | [diff] [blame] | 656 | if (!((src | dest | len) & 7)) |
| 657 | src_width = dst_width = 3; |
| 658 | else if (!((src | dest | len) & 3)) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 659 | src_width = dst_width = 2; |
| 660 | else if (!((src | dest | len) & 1)) |
| 661 | src_width = dst_width = 1; |
| 662 | else |
| 663 | src_width = dst_width = 0; |
| 664 | |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 665 | ctllo = DWC_DEFAULT_CTLLO(chan) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 666 | | DWC_CTLL_DST_WIDTH(dst_width) |
| 667 | | DWC_CTLL_SRC_WIDTH(src_width) |
| 668 | | DWC_CTLL_DST_INC |
| 669 | | DWC_CTLL_SRC_INC |
| 670 | | DWC_CTLL_FC_M2M; |
| 671 | prev = first = NULL; |
| 672 | |
| 673 | for (offset = 0; offset < len; offset += xfer_count << src_width) { |
| 674 | xfer_count = min_t(size_t, (len - offset) >> src_width, |
| 675 | DWC_MAX_COUNT); |
| 676 | |
| 677 | desc = dwc_desc_get(dwc); |
| 678 | if (!desc) |
| 679 | goto err_desc_get; |
| 680 | |
| 681 | desc->lli.sar = src + offset; |
| 682 | desc->lli.dar = dest + offset; |
| 683 | desc->lli.ctllo = ctllo; |
| 684 | desc->lli.ctlhi = xfer_count; |
| 685 | |
| 686 | if (!first) { |
| 687 | first = desc; |
| 688 | } else { |
| 689 | prev->lli.llp = desc->txd.phys; |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 690 | dma_sync_single_for_device(chan2parent(chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 691 | prev->txd.phys, sizeof(prev->lli), |
| 692 | DMA_TO_DEVICE); |
| 693 | list_add_tail(&desc->desc_node, |
Dan Williams | e0bd0f8 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 694 | &first->tx_list); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 695 | } |
| 696 | prev = desc; |
| 697 | } |
| 698 | |
| 699 | |
| 700 | if (flags & DMA_PREP_INTERRUPT) |
| 701 | /* Trigger interrupt after last block */ |
| 702 | prev->lli.ctllo |= DWC_CTLL_INT_EN; |
| 703 | |
| 704 | prev->lli.llp = 0; |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 705 | dma_sync_single_for_device(chan2parent(chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 706 | prev->txd.phys, sizeof(prev->lli), |
| 707 | DMA_TO_DEVICE); |
| 708 | |
| 709 | first->txd.flags = flags; |
| 710 | first->len = len; |
| 711 | |
| 712 | return &first->txd; |
| 713 | |
| 714 | err_desc_get: |
| 715 | dwc_desc_put(dwc, first); |
| 716 | return NULL; |
| 717 | } |
| 718 | |
| 719 | static struct dma_async_tx_descriptor * |
| 720 | dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 721 | unsigned int sg_len, enum dma_transfer_direction direction, |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 722 | unsigned long flags) |
| 723 | { |
| 724 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
Dan Williams | 287d859 | 2009-02-18 14:48:26 -0800 | [diff] [blame] | 725 | struct dw_dma_slave *dws = chan->private; |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 726 | struct dma_slave_config *sconfig = &dwc->dma_sconfig; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 727 | struct dw_desc *prev; |
| 728 | struct dw_desc *first; |
| 729 | u32 ctllo; |
| 730 | dma_addr_t reg; |
| 731 | unsigned int reg_width; |
| 732 | unsigned int mem_width; |
| 733 | unsigned int i; |
| 734 | struct scatterlist *sg; |
| 735 | size_t total_len = 0; |
| 736 | |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 737 | dev_vdbg(chan2dev(chan), "prep_dma_slave\n"); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 738 | |
| 739 | if (unlikely(!dws || !sg_len)) |
| 740 | return NULL; |
| 741 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 742 | prev = first = NULL; |
| 743 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 744 | switch (direction) { |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 745 | case DMA_MEM_TO_DEV: |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 746 | reg_width = __fls(sconfig->dst_addr_width); |
| 747 | reg = sconfig->dst_addr; |
| 748 | ctllo = (DWC_DEFAULT_CTLLO(chan) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 749 | | DWC_CTLL_DST_WIDTH(reg_width) |
| 750 | | DWC_CTLL_DST_FIX |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 751 | | DWC_CTLL_SRC_INC); |
| 752 | |
| 753 | ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_M2P) : |
| 754 | DWC_CTLL_FC(DW_DMA_FC_D_M2P); |
| 755 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 756 | for_each_sg(sgl, sg, sg_len, i) { |
| 757 | struct dw_desc *desc; |
Viresh Kumar | 69dc14b | 2011-04-18 14:54:56 +0530 | [diff] [blame] | 758 | u32 len, dlen, mem; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 759 | |
| 760 | mem = sg_phys(sg); |
| 761 | len = sg_dma_len(sg); |
Viresh Kumar | 6bc711f | 2012-02-01 16:12:25 +0530 | [diff] [blame] | 762 | |
| 763 | if (!((mem | len) & 7)) |
| 764 | mem_width = 3; |
| 765 | else if (!((mem | len) & 3)) |
| 766 | mem_width = 2; |
| 767 | else if (!((mem | len) & 1)) |
| 768 | mem_width = 1; |
| 769 | else |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 770 | mem_width = 0; |
| 771 | |
Viresh Kumar | 69dc14b | 2011-04-18 14:54:56 +0530 | [diff] [blame] | 772 | slave_sg_todev_fill_desc: |
| 773 | desc = dwc_desc_get(dwc); |
| 774 | if (!desc) { |
| 775 | dev_err(chan2dev(chan), |
| 776 | "not enough descriptors available\n"); |
| 777 | goto err_desc_get; |
| 778 | } |
| 779 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 780 | desc->lli.sar = mem; |
| 781 | desc->lli.dar = reg; |
| 782 | desc->lli.ctllo = ctllo | DWC_CTLL_SRC_WIDTH(mem_width); |
Viresh Kumar | 69dc14b | 2011-04-18 14:54:56 +0530 | [diff] [blame] | 783 | if ((len >> mem_width) > DWC_MAX_COUNT) { |
| 784 | dlen = DWC_MAX_COUNT << mem_width; |
| 785 | mem += dlen; |
| 786 | len -= dlen; |
| 787 | } else { |
| 788 | dlen = len; |
| 789 | len = 0; |
| 790 | } |
| 791 | |
| 792 | desc->lli.ctlhi = dlen >> mem_width; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 793 | |
| 794 | if (!first) { |
| 795 | first = desc; |
| 796 | } else { |
| 797 | prev->lli.llp = desc->txd.phys; |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 798 | dma_sync_single_for_device(chan2parent(chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 799 | prev->txd.phys, |
| 800 | sizeof(prev->lli), |
| 801 | DMA_TO_DEVICE); |
| 802 | list_add_tail(&desc->desc_node, |
Dan Williams | e0bd0f8 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 803 | &first->tx_list); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 804 | } |
| 805 | prev = desc; |
Viresh Kumar | 69dc14b | 2011-04-18 14:54:56 +0530 | [diff] [blame] | 806 | total_len += dlen; |
| 807 | |
| 808 | if (len) |
| 809 | goto slave_sg_todev_fill_desc; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 810 | } |
| 811 | break; |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 812 | case DMA_DEV_TO_MEM: |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 813 | reg_width = __fls(sconfig->src_addr_width); |
| 814 | reg = sconfig->src_addr; |
| 815 | ctllo = (DWC_DEFAULT_CTLLO(chan) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 816 | | DWC_CTLL_SRC_WIDTH(reg_width) |
| 817 | | DWC_CTLL_DST_INC |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 818 | | DWC_CTLL_SRC_FIX); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 819 | |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 820 | ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_P2M) : |
| 821 | DWC_CTLL_FC(DW_DMA_FC_D_P2M); |
| 822 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 823 | for_each_sg(sgl, sg, sg_len, i) { |
| 824 | struct dw_desc *desc; |
Viresh Kumar | 69dc14b | 2011-04-18 14:54:56 +0530 | [diff] [blame] | 825 | u32 len, dlen, mem; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 826 | |
| 827 | mem = sg_phys(sg); |
| 828 | len = sg_dma_len(sg); |
Viresh Kumar | 6bc711f | 2012-02-01 16:12:25 +0530 | [diff] [blame] | 829 | |
| 830 | if (!((mem | len) & 7)) |
| 831 | mem_width = 3; |
| 832 | else if (!((mem | len) & 3)) |
| 833 | mem_width = 2; |
| 834 | else if (!((mem | len) & 1)) |
| 835 | mem_width = 1; |
| 836 | else |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 837 | mem_width = 0; |
| 838 | |
Viresh Kumar | 69dc14b | 2011-04-18 14:54:56 +0530 | [diff] [blame] | 839 | slave_sg_fromdev_fill_desc: |
| 840 | desc = dwc_desc_get(dwc); |
| 841 | if (!desc) { |
| 842 | dev_err(chan2dev(chan), |
| 843 | "not enough descriptors available\n"); |
| 844 | goto err_desc_get; |
| 845 | } |
| 846 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 847 | desc->lli.sar = reg; |
| 848 | desc->lli.dar = mem; |
| 849 | desc->lli.ctllo = ctllo | DWC_CTLL_DST_WIDTH(mem_width); |
Viresh Kumar | 69dc14b | 2011-04-18 14:54:56 +0530 | [diff] [blame] | 850 | if ((len >> reg_width) > DWC_MAX_COUNT) { |
| 851 | dlen = DWC_MAX_COUNT << reg_width; |
| 852 | mem += dlen; |
| 853 | len -= dlen; |
| 854 | } else { |
| 855 | dlen = len; |
| 856 | len = 0; |
| 857 | } |
| 858 | desc->lli.ctlhi = dlen >> reg_width; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 859 | |
| 860 | if (!first) { |
| 861 | first = desc; |
| 862 | } else { |
| 863 | prev->lli.llp = desc->txd.phys; |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 864 | dma_sync_single_for_device(chan2parent(chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 865 | prev->txd.phys, |
| 866 | sizeof(prev->lli), |
| 867 | DMA_TO_DEVICE); |
| 868 | list_add_tail(&desc->desc_node, |
Dan Williams | e0bd0f8 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 869 | &first->tx_list); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 870 | } |
| 871 | prev = desc; |
Viresh Kumar | 69dc14b | 2011-04-18 14:54:56 +0530 | [diff] [blame] | 872 | total_len += dlen; |
| 873 | |
| 874 | if (len) |
| 875 | goto slave_sg_fromdev_fill_desc; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 876 | } |
| 877 | break; |
| 878 | default: |
| 879 | return NULL; |
| 880 | } |
| 881 | |
| 882 | if (flags & DMA_PREP_INTERRUPT) |
| 883 | /* Trigger interrupt after last block */ |
| 884 | prev->lli.ctllo |= DWC_CTLL_INT_EN; |
| 885 | |
| 886 | prev->lli.llp = 0; |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 887 | dma_sync_single_for_device(chan2parent(chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 888 | prev->txd.phys, sizeof(prev->lli), |
| 889 | DMA_TO_DEVICE); |
| 890 | |
| 891 | first->len = total_len; |
| 892 | |
| 893 | return &first->txd; |
| 894 | |
| 895 | err_desc_get: |
| 896 | dwc_desc_put(dwc, first); |
| 897 | return NULL; |
| 898 | } |
| 899 | |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 900 | /* |
| 901 | * Fix sconfig's burst size according to dw_dmac. We need to convert them as: |
| 902 | * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3. |
| 903 | * |
| 904 | * NOTE: burst size 2 is not supported by controller. |
| 905 | * |
| 906 | * This can be done by finding least significant bit set: n & (n - 1) |
| 907 | */ |
| 908 | static inline void convert_burst(u32 *maxburst) |
| 909 | { |
| 910 | if (*maxburst > 1) |
| 911 | *maxburst = fls(*maxburst) - 2; |
| 912 | else |
| 913 | *maxburst = 0; |
| 914 | } |
| 915 | |
| 916 | static int |
| 917 | set_runtime_config(struct dma_chan *chan, struct dma_slave_config *sconfig) |
| 918 | { |
| 919 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 920 | |
| 921 | /* Check if it is chan is configured for slave transfers */ |
| 922 | if (!chan->private) |
| 923 | return -EINVAL; |
| 924 | |
| 925 | memcpy(&dwc->dma_sconfig, sconfig, sizeof(*sconfig)); |
| 926 | |
| 927 | convert_burst(&dwc->dma_sconfig.src_maxburst); |
| 928 | convert_burst(&dwc->dma_sconfig.dst_maxburst); |
| 929 | |
| 930 | return 0; |
| 931 | } |
| 932 | |
Linus Walleij | 0582763 | 2010-05-17 16:30:42 -0700 | [diff] [blame] | 933 | static int dwc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, |
| 934 | unsigned long arg) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 935 | { |
| 936 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 937 | struct dw_dma *dw = to_dw_dma(chan->device); |
| 938 | struct dw_desc *desc, *_desc; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 939 | unsigned long flags; |
Linus Walleij | a7c57cf | 2011-04-19 08:31:32 +0800 | [diff] [blame] | 940 | u32 cfglo; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 941 | LIST_HEAD(list); |
| 942 | |
Linus Walleij | a7c57cf | 2011-04-19 08:31:32 +0800 | [diff] [blame] | 943 | if (cmd == DMA_PAUSE) { |
| 944 | spin_lock_irqsave(&dwc->lock, flags); |
| 945 | |
| 946 | cfglo = channel_readl(dwc, CFG_LO); |
| 947 | channel_writel(dwc, CFG_LO, cfglo | DWC_CFGL_CH_SUSP); |
| 948 | while (!(channel_readl(dwc, CFG_LO) & DWC_CFGL_FIFO_EMPTY)) |
| 949 | cpu_relax(); |
| 950 | |
| 951 | dwc->paused = true; |
| 952 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 953 | } else if (cmd == DMA_RESUME) { |
| 954 | if (!dwc->paused) |
| 955 | return 0; |
| 956 | |
| 957 | spin_lock_irqsave(&dwc->lock, flags); |
| 958 | |
| 959 | cfglo = channel_readl(dwc, CFG_LO); |
| 960 | channel_writel(dwc, CFG_LO, cfglo & ~DWC_CFGL_CH_SUSP); |
| 961 | dwc->paused = false; |
| 962 | |
| 963 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 964 | } else if (cmd == DMA_TERMINATE_ALL) { |
| 965 | spin_lock_irqsave(&dwc->lock, flags); |
| 966 | |
| 967 | channel_clear_bit(dw, CH_EN, dwc->mask); |
| 968 | while (dma_readl(dw, CH_EN) & dwc->mask) |
| 969 | cpu_relax(); |
| 970 | |
| 971 | dwc->paused = false; |
| 972 | |
| 973 | /* active_list entries will end up before queued entries */ |
| 974 | list_splice_init(&dwc->queue, &list); |
| 975 | list_splice_init(&dwc->active_list, &list); |
| 976 | |
| 977 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 978 | |
| 979 | /* Flush all pending and queued descriptors */ |
| 980 | list_for_each_entry_safe(desc, _desc, &list, desc_node) |
| 981 | dwc_descriptor_complete(dwc, desc, false); |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 982 | } else if (cmd == DMA_SLAVE_CONFIG) { |
| 983 | return set_runtime_config(chan, (struct dma_slave_config *)arg); |
| 984 | } else { |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 985 | return -ENXIO; |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 986 | } |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 987 | |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 988 | return 0; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | static enum dma_status |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 992 | dwc_tx_status(struct dma_chan *chan, |
| 993 | dma_cookie_t cookie, |
| 994 | struct dma_tx_state *txstate) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 995 | { |
| 996 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 997 | dma_cookie_t last_used; |
| 998 | dma_cookie_t last_complete; |
| 999 | int ret; |
| 1000 | |
Russell King - ARM Linux | 4d4e58d | 2012-03-06 22:34:06 +0000 | [diff] [blame] | 1001 | last_complete = chan->completed_cookie; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1002 | last_used = chan->cookie; |
| 1003 | |
| 1004 | ret = dma_async_is_complete(cookie, last_complete, last_used); |
| 1005 | if (ret != DMA_SUCCESS) { |
| 1006 | dwc_scan_descriptors(to_dw_dma(chan->device), dwc); |
| 1007 | |
Russell King - ARM Linux | 4d4e58d | 2012-03-06 22:34:06 +0000 | [diff] [blame] | 1008 | last_complete = chan->completed_cookie; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1009 | last_used = chan->cookie; |
| 1010 | |
| 1011 | ret = dma_async_is_complete(cookie, last_complete, last_used); |
| 1012 | } |
| 1013 | |
Viresh Kumar | abf5390 | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1014 | if (ret != DMA_SUCCESS) |
| 1015 | dma_set_tx_state(txstate, last_complete, last_used, |
| 1016 | dwc_first_active(dwc)->len); |
| 1017 | else |
| 1018 | dma_set_tx_state(txstate, last_complete, last_used, 0); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1019 | |
Linus Walleij | a7c57cf | 2011-04-19 08:31:32 +0800 | [diff] [blame] | 1020 | if (dwc->paused) |
| 1021 | return DMA_PAUSED; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1022 | |
| 1023 | return ret; |
| 1024 | } |
| 1025 | |
| 1026 | static void dwc_issue_pending(struct dma_chan *chan) |
| 1027 | { |
| 1028 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 1029 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1030 | if (!list_empty(&dwc->queue)) |
| 1031 | dwc_scan_descriptors(to_dw_dma(chan->device), dwc); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
Dan Williams | aa1e6f1 | 2009-01-06 11:38:17 -0700 | [diff] [blame] | 1034 | static int dwc_alloc_chan_resources(struct dma_chan *chan) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1035 | { |
| 1036 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 1037 | struct dw_dma *dw = to_dw_dma(chan->device); |
| 1038 | struct dw_desc *desc; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1039 | int i; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1040 | unsigned long flags; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1041 | |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 1042 | dev_vdbg(chan2dev(chan), "alloc_chan_resources\n"); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1043 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1044 | /* ASSERT: channel is idle */ |
| 1045 | if (dma_readl(dw, CH_EN) & dwc->mask) { |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 1046 | dev_dbg(chan2dev(chan), "DMA channel not idle?\n"); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1047 | return -EIO; |
| 1048 | } |
| 1049 | |
Russell King - ARM Linux | 4d4e58d | 2012-03-06 22:34:06 +0000 | [diff] [blame] | 1050 | chan->completed_cookie = chan->cookie = 1; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1051 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1052 | /* |
| 1053 | * NOTE: some controllers may have additional features that we |
| 1054 | * need to initialize here, like "scatter-gather" (which |
| 1055 | * doesn't mean what you think it means), and status writeback. |
| 1056 | */ |
| 1057 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1058 | spin_lock_irqsave(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1059 | i = dwc->descs_allocated; |
| 1060 | while (dwc->descs_allocated < NR_DESCS_PER_CHANNEL) { |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1061 | spin_unlock_irqrestore(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1062 | |
| 1063 | desc = kzalloc(sizeof(struct dw_desc), GFP_KERNEL); |
| 1064 | if (!desc) { |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 1065 | dev_info(chan2dev(chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1066 | "only allocated %d descriptors\n", i); |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1067 | spin_lock_irqsave(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1068 | break; |
| 1069 | } |
| 1070 | |
Dan Williams | e0bd0f8 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 1071 | INIT_LIST_HEAD(&desc->tx_list); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1072 | dma_async_tx_descriptor_init(&desc->txd, chan); |
| 1073 | desc->txd.tx_submit = dwc_tx_submit; |
| 1074 | desc->txd.flags = DMA_CTRL_ACK; |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 1075 | desc->txd.phys = dma_map_single(chan2parent(chan), &desc->lli, |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1076 | sizeof(desc->lli), DMA_TO_DEVICE); |
| 1077 | dwc_desc_put(dwc, desc); |
| 1078 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1079 | spin_lock_irqsave(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1080 | i = ++dwc->descs_allocated; |
| 1081 | } |
| 1082 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1083 | spin_unlock_irqrestore(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1084 | |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 1085 | dev_dbg(chan2dev(chan), |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1086 | "alloc_chan_resources allocated %d descriptors\n", i); |
| 1087 | |
| 1088 | return i; |
| 1089 | } |
| 1090 | |
| 1091 | static void dwc_free_chan_resources(struct dma_chan *chan) |
| 1092 | { |
| 1093 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 1094 | struct dw_dma *dw = to_dw_dma(chan->device); |
| 1095 | struct dw_desc *desc, *_desc; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1096 | unsigned long flags; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1097 | LIST_HEAD(list); |
| 1098 | |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 1099 | dev_dbg(chan2dev(chan), "free_chan_resources (descs allocated=%u)\n", |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1100 | dwc->descs_allocated); |
| 1101 | |
| 1102 | /* ASSERT: channel is idle */ |
| 1103 | BUG_ON(!list_empty(&dwc->active_list)); |
| 1104 | BUG_ON(!list_empty(&dwc->queue)); |
| 1105 | BUG_ON(dma_readl(to_dw_dma(chan->device), CH_EN) & dwc->mask); |
| 1106 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1107 | spin_lock_irqsave(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1108 | list_splice_init(&dwc->free_list, &list); |
| 1109 | dwc->descs_allocated = 0; |
Viresh Kumar | 61e183f | 2011-11-17 16:01:29 +0530 | [diff] [blame] | 1110 | dwc->initialized = false; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1111 | |
| 1112 | /* Disable interrupts */ |
| 1113 | channel_clear_bit(dw, MASK.XFER, dwc->mask); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1114 | channel_clear_bit(dw, MASK.ERROR, dwc->mask); |
| 1115 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1116 | spin_unlock_irqrestore(&dwc->lock, flags); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1117 | |
| 1118 | list_for_each_entry_safe(desc, _desc, &list, desc_node) { |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 1119 | dev_vdbg(chan2dev(chan), " freeing descriptor %p\n", desc); |
| 1120 | dma_unmap_single(chan2parent(chan), desc->txd.phys, |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1121 | sizeof(desc->lli), DMA_TO_DEVICE); |
| 1122 | kfree(desc); |
| 1123 | } |
| 1124 | |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 1125 | dev_vdbg(chan2dev(chan), "free_chan_resources done\n"); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1128 | /* --------------------- Cyclic DMA API extensions -------------------- */ |
| 1129 | |
| 1130 | /** |
| 1131 | * dw_dma_cyclic_start - start the cyclic DMA transfer |
| 1132 | * @chan: the DMA channel to start |
| 1133 | * |
| 1134 | * Must be called with soft interrupts disabled. Returns zero on success or |
| 1135 | * -errno on failure. |
| 1136 | */ |
| 1137 | int dw_dma_cyclic_start(struct dma_chan *chan) |
| 1138 | { |
| 1139 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 1140 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1141 | unsigned long flags; |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1142 | |
| 1143 | if (!test_bit(DW_DMA_IS_CYCLIC, &dwc->flags)) { |
| 1144 | dev_err(chan2dev(&dwc->chan), "missing prep for cyclic DMA\n"); |
| 1145 | return -ENODEV; |
| 1146 | } |
| 1147 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1148 | spin_lock_irqsave(&dwc->lock, flags); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1149 | |
| 1150 | /* assert channel is idle */ |
| 1151 | if (dma_readl(dw, CH_EN) & dwc->mask) { |
| 1152 | dev_err(chan2dev(&dwc->chan), |
| 1153 | "BUG: Attempted to start non-idle channel\n"); |
| 1154 | dev_err(chan2dev(&dwc->chan), |
| 1155 | " SAR: 0x%x DAR: 0x%x LLP: 0x%x CTL: 0x%x:%08x\n", |
| 1156 | channel_readl(dwc, SAR), |
| 1157 | channel_readl(dwc, DAR), |
| 1158 | channel_readl(dwc, LLP), |
| 1159 | channel_readl(dwc, CTL_HI), |
| 1160 | channel_readl(dwc, CTL_LO)); |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1161 | spin_unlock_irqrestore(&dwc->lock, flags); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1162 | return -EBUSY; |
| 1163 | } |
| 1164 | |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1165 | dma_writel(dw, CLEAR.ERROR, dwc->mask); |
| 1166 | dma_writel(dw, CLEAR.XFER, dwc->mask); |
| 1167 | |
| 1168 | /* setup DMAC channel registers */ |
| 1169 | channel_writel(dwc, LLP, dwc->cdesc->desc[0]->txd.phys); |
| 1170 | channel_writel(dwc, CTL_LO, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN); |
| 1171 | channel_writel(dwc, CTL_HI, 0); |
| 1172 | |
| 1173 | channel_set_bit(dw, CH_EN, dwc->mask); |
| 1174 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1175 | spin_unlock_irqrestore(&dwc->lock, flags); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1176 | |
| 1177 | return 0; |
| 1178 | } |
| 1179 | EXPORT_SYMBOL(dw_dma_cyclic_start); |
| 1180 | |
| 1181 | /** |
| 1182 | * dw_dma_cyclic_stop - stop the cyclic DMA transfer |
| 1183 | * @chan: the DMA channel to stop |
| 1184 | * |
| 1185 | * Must be called with soft interrupts disabled. |
| 1186 | */ |
| 1187 | void dw_dma_cyclic_stop(struct dma_chan *chan) |
| 1188 | { |
| 1189 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 1190 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1191 | unsigned long flags; |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1192 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1193 | spin_lock_irqsave(&dwc->lock, flags); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1194 | |
| 1195 | channel_clear_bit(dw, CH_EN, dwc->mask); |
| 1196 | while (dma_readl(dw, CH_EN) & dwc->mask) |
| 1197 | cpu_relax(); |
| 1198 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1199 | spin_unlock_irqrestore(&dwc->lock, flags); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1200 | } |
| 1201 | EXPORT_SYMBOL(dw_dma_cyclic_stop); |
| 1202 | |
| 1203 | /** |
| 1204 | * dw_dma_cyclic_prep - prepare the cyclic DMA transfer |
| 1205 | * @chan: the DMA channel to prepare |
| 1206 | * @buf_addr: physical DMA address where the buffer starts |
| 1207 | * @buf_len: total number of bytes for the entire buffer |
| 1208 | * @period_len: number of bytes for each period |
| 1209 | * @direction: transfer direction, to or from device |
| 1210 | * |
| 1211 | * Must be called before trying to start the transfer. Returns a valid struct |
| 1212 | * dw_cyclic_desc if successful or an ERR_PTR(-errno) if not successful. |
| 1213 | */ |
| 1214 | struct dw_cyclic_desc *dw_dma_cyclic_prep(struct dma_chan *chan, |
| 1215 | dma_addr_t buf_addr, size_t buf_len, size_t period_len, |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1216 | enum dma_transfer_direction direction) |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1217 | { |
| 1218 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 1219 | struct dma_slave_config *sconfig = &dwc->dma_sconfig; |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1220 | struct dw_cyclic_desc *cdesc; |
| 1221 | struct dw_cyclic_desc *retval = NULL; |
| 1222 | struct dw_desc *desc; |
| 1223 | struct dw_desc *last = NULL; |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1224 | unsigned long was_cyclic; |
| 1225 | unsigned int reg_width; |
| 1226 | unsigned int periods; |
| 1227 | unsigned int i; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1228 | unsigned long flags; |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1229 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1230 | spin_lock_irqsave(&dwc->lock, flags); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1231 | if (!list_empty(&dwc->queue) || !list_empty(&dwc->active_list)) { |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1232 | spin_unlock_irqrestore(&dwc->lock, flags); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1233 | dev_dbg(chan2dev(&dwc->chan), |
| 1234 | "queue and/or active list are not empty\n"); |
| 1235 | return ERR_PTR(-EBUSY); |
| 1236 | } |
| 1237 | |
| 1238 | was_cyclic = test_and_set_bit(DW_DMA_IS_CYCLIC, &dwc->flags); |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1239 | spin_unlock_irqrestore(&dwc->lock, flags); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1240 | if (was_cyclic) { |
| 1241 | dev_dbg(chan2dev(&dwc->chan), |
| 1242 | "channel already prepared for cyclic DMA\n"); |
| 1243 | return ERR_PTR(-EBUSY); |
| 1244 | } |
| 1245 | |
| 1246 | retval = ERR_PTR(-EINVAL); |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 1247 | |
| 1248 | if (direction == DMA_MEM_TO_DEV) |
| 1249 | reg_width = __ffs(sconfig->dst_addr_width); |
| 1250 | else |
| 1251 | reg_width = __ffs(sconfig->src_addr_width); |
| 1252 | |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1253 | periods = buf_len / period_len; |
| 1254 | |
| 1255 | /* Check for too big/unaligned periods and unaligned DMA buffer. */ |
| 1256 | if (period_len > (DWC_MAX_COUNT << reg_width)) |
| 1257 | goto out_err; |
| 1258 | if (unlikely(period_len & ((1 << reg_width) - 1))) |
| 1259 | goto out_err; |
| 1260 | if (unlikely(buf_addr & ((1 << reg_width) - 1))) |
| 1261 | goto out_err; |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1262 | if (unlikely(!(direction & (DMA_MEM_TO_DEV | DMA_DEV_TO_MEM)))) |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1263 | goto out_err; |
| 1264 | |
| 1265 | retval = ERR_PTR(-ENOMEM); |
| 1266 | |
| 1267 | if (periods > NR_DESCS_PER_CHANNEL) |
| 1268 | goto out_err; |
| 1269 | |
| 1270 | cdesc = kzalloc(sizeof(struct dw_cyclic_desc), GFP_KERNEL); |
| 1271 | if (!cdesc) |
| 1272 | goto out_err; |
| 1273 | |
| 1274 | cdesc->desc = kzalloc(sizeof(struct dw_desc *) * periods, GFP_KERNEL); |
| 1275 | if (!cdesc->desc) |
| 1276 | goto out_err_alloc; |
| 1277 | |
| 1278 | for (i = 0; i < periods; i++) { |
| 1279 | desc = dwc_desc_get(dwc); |
| 1280 | if (!desc) |
| 1281 | goto out_err_desc_get; |
| 1282 | |
| 1283 | switch (direction) { |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1284 | case DMA_MEM_TO_DEV: |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 1285 | desc->lli.dar = sconfig->dst_addr; |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1286 | desc->lli.sar = buf_addr + (period_len * i); |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 1287 | desc->lli.ctllo = (DWC_DEFAULT_CTLLO(chan) |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1288 | | DWC_CTLL_DST_WIDTH(reg_width) |
| 1289 | | DWC_CTLL_SRC_WIDTH(reg_width) |
| 1290 | | DWC_CTLL_DST_FIX |
| 1291 | | DWC_CTLL_SRC_INC |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1292 | | DWC_CTLL_INT_EN); |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 1293 | |
| 1294 | desc->lli.ctllo |= sconfig->device_fc ? |
| 1295 | DWC_CTLL_FC(DW_DMA_FC_P_M2P) : |
| 1296 | DWC_CTLL_FC(DW_DMA_FC_D_M2P); |
| 1297 | |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1298 | break; |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1299 | case DMA_DEV_TO_MEM: |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1300 | desc->lli.dar = buf_addr + (period_len * i); |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 1301 | desc->lli.sar = sconfig->src_addr; |
| 1302 | desc->lli.ctllo = (DWC_DEFAULT_CTLLO(chan) |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1303 | | DWC_CTLL_SRC_WIDTH(reg_width) |
| 1304 | | DWC_CTLL_DST_WIDTH(reg_width) |
| 1305 | | DWC_CTLL_DST_INC |
| 1306 | | DWC_CTLL_SRC_FIX |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1307 | | DWC_CTLL_INT_EN); |
Viresh Kumar | 327e697 | 2012-02-01 16:12:26 +0530 | [diff] [blame] | 1308 | |
| 1309 | desc->lli.ctllo |= sconfig->device_fc ? |
| 1310 | DWC_CTLL_FC(DW_DMA_FC_P_P2M) : |
| 1311 | DWC_CTLL_FC(DW_DMA_FC_D_P2M); |
| 1312 | |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1313 | break; |
| 1314 | default: |
| 1315 | break; |
| 1316 | } |
| 1317 | |
| 1318 | desc->lli.ctlhi = (period_len >> reg_width); |
| 1319 | cdesc->desc[i] = desc; |
| 1320 | |
| 1321 | if (last) { |
| 1322 | last->lli.llp = desc->txd.phys; |
| 1323 | dma_sync_single_for_device(chan2parent(chan), |
| 1324 | last->txd.phys, sizeof(last->lli), |
| 1325 | DMA_TO_DEVICE); |
| 1326 | } |
| 1327 | |
| 1328 | last = desc; |
| 1329 | } |
| 1330 | |
| 1331 | /* lets make a cyclic list */ |
| 1332 | last->lli.llp = cdesc->desc[0]->txd.phys; |
| 1333 | dma_sync_single_for_device(chan2parent(chan), last->txd.phys, |
| 1334 | sizeof(last->lli), DMA_TO_DEVICE); |
| 1335 | |
| 1336 | dev_dbg(chan2dev(&dwc->chan), "cyclic prepared buf 0x%08x len %zu " |
| 1337 | "period %zu periods %d\n", buf_addr, buf_len, |
| 1338 | period_len, periods); |
| 1339 | |
| 1340 | cdesc->periods = periods; |
| 1341 | dwc->cdesc = cdesc; |
| 1342 | |
| 1343 | return cdesc; |
| 1344 | |
| 1345 | out_err_desc_get: |
| 1346 | while (i--) |
| 1347 | dwc_desc_put(dwc, cdesc->desc[i]); |
| 1348 | out_err_alloc: |
| 1349 | kfree(cdesc); |
| 1350 | out_err: |
| 1351 | clear_bit(DW_DMA_IS_CYCLIC, &dwc->flags); |
| 1352 | return (struct dw_cyclic_desc *)retval; |
| 1353 | } |
| 1354 | EXPORT_SYMBOL(dw_dma_cyclic_prep); |
| 1355 | |
| 1356 | /** |
| 1357 | * dw_dma_cyclic_free - free a prepared cyclic DMA transfer |
| 1358 | * @chan: the DMA channel to free |
| 1359 | */ |
| 1360 | void dw_dma_cyclic_free(struct dma_chan *chan) |
| 1361 | { |
| 1362 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
| 1363 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); |
| 1364 | struct dw_cyclic_desc *cdesc = dwc->cdesc; |
| 1365 | int i; |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1366 | unsigned long flags; |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1367 | |
| 1368 | dev_dbg(chan2dev(&dwc->chan), "cyclic free\n"); |
| 1369 | |
| 1370 | if (!cdesc) |
| 1371 | return; |
| 1372 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1373 | spin_lock_irqsave(&dwc->lock, flags); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1374 | |
| 1375 | channel_clear_bit(dw, CH_EN, dwc->mask); |
| 1376 | while (dma_readl(dw, CH_EN) & dwc->mask) |
| 1377 | cpu_relax(); |
| 1378 | |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1379 | dma_writel(dw, CLEAR.ERROR, dwc->mask); |
| 1380 | dma_writel(dw, CLEAR.XFER, dwc->mask); |
| 1381 | |
Viresh Kumar | 69cea5a | 2011-04-15 16:03:35 +0530 | [diff] [blame] | 1382 | spin_unlock_irqrestore(&dwc->lock, flags); |
Hans-Christian Egtvedt | d9de451 | 2009-04-01 15:47:02 +0200 | [diff] [blame] | 1383 | |
| 1384 | for (i = 0; i < cdesc->periods; i++) |
| 1385 | dwc_desc_put(dwc, cdesc->desc[i]); |
| 1386 | |
| 1387 | kfree(cdesc->desc); |
| 1388 | kfree(cdesc); |
| 1389 | |
| 1390 | clear_bit(DW_DMA_IS_CYCLIC, &dwc->flags); |
| 1391 | } |
| 1392 | EXPORT_SYMBOL(dw_dma_cyclic_free); |
| 1393 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1394 | /*----------------------------------------------------------------------*/ |
| 1395 | |
| 1396 | static void dw_dma_off(struct dw_dma *dw) |
| 1397 | { |
Viresh Kumar | 61e183f | 2011-11-17 16:01:29 +0530 | [diff] [blame] | 1398 | int i; |
| 1399 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1400 | dma_writel(dw, CFG, 0); |
| 1401 | |
| 1402 | channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1403 | channel_clear_bit(dw, MASK.SRC_TRAN, dw->all_chan_mask); |
| 1404 | channel_clear_bit(dw, MASK.DST_TRAN, dw->all_chan_mask); |
| 1405 | channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask); |
| 1406 | |
| 1407 | while (dma_readl(dw, CFG) & DW_CFG_DMA_EN) |
| 1408 | cpu_relax(); |
Viresh Kumar | 61e183f | 2011-11-17 16:01:29 +0530 | [diff] [blame] | 1409 | |
| 1410 | for (i = 0; i < dw->dma.chancnt; i++) |
| 1411 | dw->chan[i].initialized = false; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | static int __init dw_probe(struct platform_device *pdev) |
| 1415 | { |
| 1416 | struct dw_dma_platform_data *pdata; |
| 1417 | struct resource *io; |
| 1418 | struct dw_dma *dw; |
| 1419 | size_t size; |
| 1420 | int irq; |
| 1421 | int err; |
| 1422 | int i; |
| 1423 | |
Viresh Kumar | 6c618c9 | 2012-02-01 16:12:22 +0530 | [diff] [blame] | 1424 | pdata = dev_get_platdata(&pdev->dev); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1425 | if (!pdata || pdata->nr_channels > DW_DMA_MAX_NR_CHANNELS) |
| 1426 | return -EINVAL; |
| 1427 | |
| 1428 | io = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1429 | if (!io) |
| 1430 | return -EINVAL; |
| 1431 | |
| 1432 | irq = platform_get_irq(pdev, 0); |
| 1433 | if (irq < 0) |
| 1434 | return irq; |
| 1435 | |
| 1436 | size = sizeof(struct dw_dma); |
| 1437 | size += pdata->nr_channels * sizeof(struct dw_dma_chan); |
| 1438 | dw = kzalloc(size, GFP_KERNEL); |
| 1439 | if (!dw) |
| 1440 | return -ENOMEM; |
| 1441 | |
| 1442 | if (!request_mem_region(io->start, DW_REGLEN, pdev->dev.driver->name)) { |
| 1443 | err = -EBUSY; |
| 1444 | goto err_kfree; |
| 1445 | } |
| 1446 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1447 | dw->regs = ioremap(io->start, DW_REGLEN); |
| 1448 | if (!dw->regs) { |
| 1449 | err = -ENOMEM; |
| 1450 | goto err_release_r; |
| 1451 | } |
| 1452 | |
| 1453 | dw->clk = clk_get(&pdev->dev, "hclk"); |
| 1454 | if (IS_ERR(dw->clk)) { |
| 1455 | err = PTR_ERR(dw->clk); |
| 1456 | goto err_clk; |
| 1457 | } |
| 1458 | clk_enable(dw->clk); |
| 1459 | |
| 1460 | /* force dma off, just in case */ |
| 1461 | dw_dma_off(dw); |
| 1462 | |
| 1463 | err = request_irq(irq, dw_dma_interrupt, 0, "dw_dmac", dw); |
| 1464 | if (err) |
| 1465 | goto err_irq; |
| 1466 | |
| 1467 | platform_set_drvdata(pdev, dw); |
| 1468 | |
| 1469 | tasklet_init(&dw->tasklet, dw_dma_tasklet, (unsigned long)dw); |
| 1470 | |
| 1471 | dw->all_chan_mask = (1 << pdata->nr_channels) - 1; |
| 1472 | |
| 1473 | INIT_LIST_HEAD(&dw->dma.channels); |
Barry Song | 46389470 | 2011-09-15 03:06:30 -0700 | [diff] [blame] | 1474 | for (i = 0; i < pdata->nr_channels; i++) { |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1475 | struct dw_dma_chan *dwc = &dw->chan[i]; |
| 1476 | |
| 1477 | dwc->chan.device = &dw->dma; |
Russell King - ARM Linux | 4d4e58d | 2012-03-06 22:34:06 +0000 | [diff] [blame] | 1478 | dwc->chan.cookie = dwc->chan.completed_cookie = 1; |
Viresh Kumar | b0c3130 | 2011-03-03 15:47:21 +0530 | [diff] [blame] | 1479 | if (pdata->chan_allocation_order == CHAN_ALLOCATION_ASCENDING) |
| 1480 | list_add_tail(&dwc->chan.device_node, |
| 1481 | &dw->dma.channels); |
| 1482 | else |
| 1483 | list_add(&dwc->chan.device_node, &dw->dma.channels); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1484 | |
Viresh Kumar | 93317e8 | 2011-03-03 15:47:22 +0530 | [diff] [blame] | 1485 | /* 7 is highest priority & 0 is lowest. */ |
| 1486 | if (pdata->chan_priority == CHAN_PRIORITY_ASCENDING) |
Viresh Kumar | e8d9f87 | 2012-02-01 16:12:21 +0530 | [diff] [blame] | 1487 | dwc->priority = pdata->nr_channels - i - 1; |
Viresh Kumar | 93317e8 | 2011-03-03 15:47:22 +0530 | [diff] [blame] | 1488 | else |
| 1489 | dwc->priority = i; |
| 1490 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1491 | dwc->ch_regs = &__dw_regs(dw)->CHAN[i]; |
| 1492 | spin_lock_init(&dwc->lock); |
| 1493 | dwc->mask = 1 << i; |
| 1494 | |
| 1495 | INIT_LIST_HEAD(&dwc->active_list); |
| 1496 | INIT_LIST_HEAD(&dwc->queue); |
| 1497 | INIT_LIST_HEAD(&dwc->free_list); |
| 1498 | |
| 1499 | channel_clear_bit(dw, CH_EN, dwc->mask); |
| 1500 | } |
| 1501 | |
| 1502 | /* Clear/disable all interrupts on all channels. */ |
| 1503 | dma_writel(dw, CLEAR.XFER, dw->all_chan_mask); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1504 | dma_writel(dw, CLEAR.SRC_TRAN, dw->all_chan_mask); |
| 1505 | dma_writel(dw, CLEAR.DST_TRAN, dw->all_chan_mask); |
| 1506 | dma_writel(dw, CLEAR.ERROR, dw->all_chan_mask); |
| 1507 | |
| 1508 | channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1509 | channel_clear_bit(dw, MASK.SRC_TRAN, dw->all_chan_mask); |
| 1510 | channel_clear_bit(dw, MASK.DST_TRAN, dw->all_chan_mask); |
| 1511 | channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask); |
| 1512 | |
| 1513 | dma_cap_set(DMA_MEMCPY, dw->dma.cap_mask); |
| 1514 | dma_cap_set(DMA_SLAVE, dw->dma.cap_mask); |
Jamie Iles | 95ea759 | 2011-01-21 14:11:54 +0000 | [diff] [blame] | 1515 | if (pdata->is_private) |
| 1516 | dma_cap_set(DMA_PRIVATE, dw->dma.cap_mask); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1517 | dw->dma.dev = &pdev->dev; |
| 1518 | dw->dma.device_alloc_chan_resources = dwc_alloc_chan_resources; |
| 1519 | dw->dma.device_free_chan_resources = dwc_free_chan_resources; |
| 1520 | |
| 1521 | dw->dma.device_prep_dma_memcpy = dwc_prep_dma_memcpy; |
| 1522 | |
| 1523 | dw->dma.device_prep_slave_sg = dwc_prep_slave_sg; |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 1524 | dw->dma.device_control = dwc_control; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1525 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1526 | dw->dma.device_tx_status = dwc_tx_status; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1527 | dw->dma.device_issue_pending = dwc_issue_pending; |
| 1528 | |
| 1529 | dma_writel(dw, CFG, DW_CFG_DMA_EN); |
| 1530 | |
| 1531 | printk(KERN_INFO "%s: DesignWare DMA Controller, %d channels\n", |
Barry Song | 46389470 | 2011-09-15 03:06:30 -0700 | [diff] [blame] | 1532 | dev_name(&pdev->dev), pdata->nr_channels); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1533 | |
| 1534 | dma_async_device_register(&dw->dma); |
| 1535 | |
| 1536 | return 0; |
| 1537 | |
| 1538 | err_irq: |
| 1539 | clk_disable(dw->clk); |
| 1540 | clk_put(dw->clk); |
| 1541 | err_clk: |
| 1542 | iounmap(dw->regs); |
| 1543 | dw->regs = NULL; |
| 1544 | err_release_r: |
| 1545 | release_resource(io); |
| 1546 | err_kfree: |
| 1547 | kfree(dw); |
| 1548 | return err; |
| 1549 | } |
| 1550 | |
| 1551 | static int __exit dw_remove(struct platform_device *pdev) |
| 1552 | { |
| 1553 | struct dw_dma *dw = platform_get_drvdata(pdev); |
| 1554 | struct dw_dma_chan *dwc, *_dwc; |
| 1555 | struct resource *io; |
| 1556 | |
| 1557 | dw_dma_off(dw); |
| 1558 | dma_async_device_unregister(&dw->dma); |
| 1559 | |
| 1560 | free_irq(platform_get_irq(pdev, 0), dw); |
| 1561 | tasklet_kill(&dw->tasklet); |
| 1562 | |
| 1563 | list_for_each_entry_safe(dwc, _dwc, &dw->dma.channels, |
| 1564 | chan.device_node) { |
| 1565 | list_del(&dwc->chan.device_node); |
| 1566 | channel_clear_bit(dw, CH_EN, dwc->mask); |
| 1567 | } |
| 1568 | |
| 1569 | clk_disable(dw->clk); |
| 1570 | clk_put(dw->clk); |
| 1571 | |
| 1572 | iounmap(dw->regs); |
| 1573 | dw->regs = NULL; |
| 1574 | |
| 1575 | io = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1576 | release_mem_region(io->start, DW_REGLEN); |
| 1577 | |
| 1578 | kfree(dw); |
| 1579 | |
| 1580 | return 0; |
| 1581 | } |
| 1582 | |
| 1583 | static void dw_shutdown(struct platform_device *pdev) |
| 1584 | { |
| 1585 | struct dw_dma *dw = platform_get_drvdata(pdev); |
| 1586 | |
| 1587 | dw_dma_off(platform_get_drvdata(pdev)); |
| 1588 | clk_disable(dw->clk); |
| 1589 | } |
| 1590 | |
Magnus Damm | 4a256b5 | 2009-07-08 13:22:18 +0200 | [diff] [blame] | 1591 | static int dw_suspend_noirq(struct device *dev) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1592 | { |
Magnus Damm | 4a256b5 | 2009-07-08 13:22:18 +0200 | [diff] [blame] | 1593 | struct platform_device *pdev = to_platform_device(dev); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1594 | struct dw_dma *dw = platform_get_drvdata(pdev); |
| 1595 | |
| 1596 | dw_dma_off(platform_get_drvdata(pdev)); |
| 1597 | clk_disable(dw->clk); |
Viresh Kumar | 61e183f | 2011-11-17 16:01:29 +0530 | [diff] [blame] | 1598 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1599 | return 0; |
| 1600 | } |
| 1601 | |
Magnus Damm | 4a256b5 | 2009-07-08 13:22:18 +0200 | [diff] [blame] | 1602 | static int dw_resume_noirq(struct device *dev) |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1603 | { |
Magnus Damm | 4a256b5 | 2009-07-08 13:22:18 +0200 | [diff] [blame] | 1604 | struct platform_device *pdev = to_platform_device(dev); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1605 | struct dw_dma *dw = platform_get_drvdata(pdev); |
| 1606 | |
| 1607 | clk_enable(dw->clk); |
| 1608 | dma_writel(dw, CFG, DW_CFG_DMA_EN); |
| 1609 | return 0; |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1612 | static const struct dev_pm_ops dw_dev_pm_ops = { |
Magnus Damm | 4a256b5 | 2009-07-08 13:22:18 +0200 | [diff] [blame] | 1613 | .suspend_noirq = dw_suspend_noirq, |
| 1614 | .resume_noirq = dw_resume_noirq, |
Rajeev KUMAR | 7414a1b | 2012-02-01 16:12:17 +0530 | [diff] [blame] | 1615 | .freeze_noirq = dw_suspend_noirq, |
| 1616 | .thaw_noirq = dw_resume_noirq, |
| 1617 | .restore_noirq = dw_resume_noirq, |
| 1618 | .poweroff_noirq = dw_suspend_noirq, |
Magnus Damm | 4a256b5 | 2009-07-08 13:22:18 +0200 | [diff] [blame] | 1619 | }; |
| 1620 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1621 | static struct platform_driver dw_driver = { |
| 1622 | .remove = __exit_p(dw_remove), |
| 1623 | .shutdown = dw_shutdown, |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1624 | .driver = { |
| 1625 | .name = "dw_dmac", |
Magnus Damm | 4a256b5 | 2009-07-08 13:22:18 +0200 | [diff] [blame] | 1626 | .pm = &dw_dev_pm_ops, |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1627 | }, |
| 1628 | }; |
| 1629 | |
| 1630 | static int __init dw_init(void) |
| 1631 | { |
| 1632 | return platform_driver_probe(&dw_driver, dw_probe); |
| 1633 | } |
Viresh Kumar | cb689a7 | 2011-03-03 15:47:15 +0530 | [diff] [blame] | 1634 | subsys_initcall(dw_init); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 1635 | |
| 1636 | static void __exit dw_exit(void) |
| 1637 | { |
| 1638 | platform_driver_unregister(&dw_driver); |
| 1639 | } |
| 1640 | module_exit(dw_exit); |
| 1641 | |
| 1642 | MODULE_LICENSE("GPL v2"); |
| 1643 | MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller driver"); |
Jean Delvare | e05503e | 2011-05-18 16:49:24 +0200 | [diff] [blame] | 1644 | MODULE_AUTHOR("Haavard Skinnemoen (Atmel)"); |
Viresh Kumar | aecb7b6 | 2011-05-24 14:04:09 +0530 | [diff] [blame] | 1645 | MODULE_AUTHOR("Viresh Kumar <viresh.kumar@st.com>"); |