Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Freescale MPC85xx, MPC83xx DMA Engine support |
| 3 | * |
Li Yang | e2c8e425 | 2010-11-11 20:16:29 +0800 | [diff] [blame] | 4 | * Copyright (C) 2007-2010 Freescale Semiconductor, Inc. All rights reserved. |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 5 | * |
| 6 | * Author: |
| 7 | * Zhang Wei <wei.zhang@freescale.com>, Jul 2007 |
| 8 | * Ebony Zhu <ebony.zhu@freescale.com>, May 2007 |
| 9 | * |
| 10 | * Description: |
| 11 | * DMA engine driver for Freescale MPC8540 DMA controller, which is |
| 12 | * also fit for MPC8560, MPC8555, MPC8548, MPC8641, and etc. |
Stefan Weil | c2e07b3 | 2010-08-03 19:44:52 +0200 | [diff] [blame] | 13 | * The support for MPC8349 DMA controller is also added. |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 14 | * |
Ira W. Snyder | a7aea37 | 2009-04-23 16:17:54 -0700 | [diff] [blame] | 15 | * This driver instructs the DMA controller to issue the PCI Read Multiple |
| 16 | * command for PCI read operations, instead of using the default PCI Read Line |
| 17 | * command. Please be aware that this setting may result in read pre-fetching |
| 18 | * on some platforms. |
| 19 | * |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 20 | * This is free software; you can redistribute it and/or modify |
| 21 | * it under the terms of the GNU General Public License as published by |
| 22 | * the Free Software Foundation; either version 2 of the License, or |
| 23 | * (at your option) any later version. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/dmaengine.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include <linux/dma-mapping.h> |
| 35 | #include <linux/dmapool.h> |
| 36 | #include <linux/of_platform.h> |
| 37 | |
| 38 | #include "fsldma.h" |
| 39 | |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 40 | #define chan_dbg(chan, fmt, arg...) \ |
| 41 | dev_dbg(chan->dev, "%s: " fmt, chan->name, ##arg) |
| 42 | #define chan_err(chan, fmt, arg...) \ |
| 43 | dev_err(chan->dev, "%s: " fmt, chan->name, ##arg) |
| 44 | |
| 45 | static const char msg_ld_oom[] = "No free memory for link descriptor"; |
Ira Snyder | c1433041 | 2010-09-30 11:46:45 +0000 | [diff] [blame] | 46 | |
Ira Snyder | e8bd84d | 2011-03-03 07:54:54 +0000 | [diff] [blame] | 47 | /* |
| 48 | * Register Helpers |
| 49 | */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 50 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 51 | static void set_sr(struct fsldma_chan *chan, u32 val) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 52 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 53 | DMA_OUT(chan, &chan->regs->sr, val, 32); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 56 | static u32 get_sr(struct fsldma_chan *chan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 57 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 58 | return DMA_IN(chan, &chan->regs->sr, 32); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Ira Snyder | e8bd84d | 2011-03-03 07:54:54 +0000 | [diff] [blame] | 61 | static void set_cdar(struct fsldma_chan *chan, dma_addr_t addr) |
| 62 | { |
| 63 | DMA_OUT(chan, &chan->regs->cdar, addr | FSL_DMA_SNEN, 64); |
| 64 | } |
| 65 | |
| 66 | static dma_addr_t get_cdar(struct fsldma_chan *chan) |
| 67 | { |
| 68 | return DMA_IN(chan, &chan->regs->cdar, 64) & ~FSL_DMA_SNEN; |
| 69 | } |
| 70 | |
Ira Snyder | e8bd84d | 2011-03-03 07:54:54 +0000 | [diff] [blame] | 71 | static u32 get_bcr(struct fsldma_chan *chan) |
| 72 | { |
| 73 | return DMA_IN(chan, &chan->regs->bcr, 32); |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Descriptor Helpers |
| 78 | */ |
| 79 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 80 | static void set_desc_cnt(struct fsldma_chan *chan, |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 81 | struct fsl_dma_ld_hw *hw, u32 count) |
| 82 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 83 | hw->count = CPU_TO_DMA(chan, count, 32); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Ira Snyder | 9c4d1e7 | 2011-03-03 07:54:59 +0000 | [diff] [blame^] | 86 | static u32 get_desc_cnt(struct fsldma_chan *chan, struct fsl_desc_sw *desc) |
| 87 | { |
| 88 | return DMA_TO_CPU(chan, desc->hw.count, 32); |
| 89 | } |
| 90 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 91 | static void set_desc_src(struct fsldma_chan *chan, |
Ira Snyder | 31f4306 | 2011-03-03 07:54:57 +0000 | [diff] [blame] | 92 | struct fsl_dma_ld_hw *hw, dma_addr_t src) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 93 | { |
| 94 | u64 snoop_bits; |
| 95 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 96 | snoop_bits = ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 97 | ? ((u64)FSL_DMA_SATR_SREADTYPE_SNOOP_READ << 32) : 0; |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 98 | hw->src_addr = CPU_TO_DMA(chan, snoop_bits | src, 64); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Ira Snyder | 9c4d1e7 | 2011-03-03 07:54:59 +0000 | [diff] [blame^] | 101 | static dma_addr_t get_desc_src(struct fsldma_chan *chan, |
| 102 | struct fsl_desc_sw *desc) |
| 103 | { |
| 104 | u64 snoop_bits; |
| 105 | |
| 106 | snoop_bits = ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) |
| 107 | ? ((u64)FSL_DMA_SATR_SREADTYPE_SNOOP_READ << 32) : 0; |
| 108 | return DMA_TO_CPU(chan, desc->hw.src_addr, 64) & ~snoop_bits; |
| 109 | } |
| 110 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 111 | static void set_desc_dst(struct fsldma_chan *chan, |
Ira Snyder | 31f4306 | 2011-03-03 07:54:57 +0000 | [diff] [blame] | 112 | struct fsl_dma_ld_hw *hw, dma_addr_t dst) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 113 | { |
| 114 | u64 snoop_bits; |
| 115 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 116 | snoop_bits = ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 117 | ? ((u64)FSL_DMA_DATR_DWRITETYPE_SNOOP_WRITE << 32) : 0; |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 118 | hw->dst_addr = CPU_TO_DMA(chan, snoop_bits | dst, 64); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Ira Snyder | 9c4d1e7 | 2011-03-03 07:54:59 +0000 | [diff] [blame^] | 121 | static dma_addr_t get_desc_dst(struct fsldma_chan *chan, |
| 122 | struct fsl_desc_sw *desc) |
| 123 | { |
| 124 | u64 snoop_bits; |
| 125 | |
| 126 | snoop_bits = ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) |
| 127 | ? ((u64)FSL_DMA_DATR_DWRITETYPE_SNOOP_WRITE << 32) : 0; |
| 128 | return DMA_TO_CPU(chan, desc->hw.dst_addr, 64) & ~snoop_bits; |
| 129 | } |
| 130 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 131 | static void set_desc_next(struct fsldma_chan *chan, |
Ira Snyder | 31f4306 | 2011-03-03 07:54:57 +0000 | [diff] [blame] | 132 | struct fsl_dma_ld_hw *hw, dma_addr_t next) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 133 | { |
| 134 | u64 snoop_bits; |
| 135 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 136 | snoop_bits = ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_83XX) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 137 | ? FSL_DMA_SNEN : 0; |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 138 | hw->next_ln_addr = CPU_TO_DMA(chan, snoop_bits | next, 64); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Ira Snyder | 31f4306 | 2011-03-03 07:54:57 +0000 | [diff] [blame] | 141 | static void set_ld_eol(struct fsldma_chan *chan, struct fsl_desc_sw *desc) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 142 | { |
Ira Snyder | e8bd84d | 2011-03-03 07:54:54 +0000 | [diff] [blame] | 143 | u64 snoop_bits; |
| 144 | |
| 145 | snoop_bits = ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_83XX) |
| 146 | ? FSL_DMA_SNEN : 0; |
| 147 | |
| 148 | desc->hw.next_ln_addr = CPU_TO_DMA(chan, |
| 149 | DMA_TO_CPU(chan, desc->hw.next_ln_addr, 64) | FSL_DMA_EOL |
| 150 | | snoop_bits, 64); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Ira Snyder | e8bd84d | 2011-03-03 07:54:54 +0000 | [diff] [blame] | 153 | /* |
| 154 | * DMA Engine Hardware Control Helpers |
| 155 | */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 156 | |
Ira Snyder | e8bd84d | 2011-03-03 07:54:54 +0000 | [diff] [blame] | 157 | static void dma_init(struct fsldma_chan *chan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 158 | { |
Ira Snyder | e8bd84d | 2011-03-03 07:54:54 +0000 | [diff] [blame] | 159 | /* Reset the channel */ |
| 160 | DMA_OUT(chan, &chan->regs->mr, 0, 32); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 161 | |
Ira Snyder | e8bd84d | 2011-03-03 07:54:54 +0000 | [diff] [blame] | 162 | switch (chan->feature & FSL_DMA_IP_MASK) { |
| 163 | case FSL_DMA_IP_85XX: |
| 164 | /* Set the channel to below modes: |
| 165 | * EIE - Error interrupt enable |
Ira Snyder | e8bd84d | 2011-03-03 07:54:54 +0000 | [diff] [blame] | 166 | * EOLNIE - End of links interrupt enable |
| 167 | * BWC - Bandwidth sharing among channels |
| 168 | */ |
| 169 | DMA_OUT(chan, &chan->regs->mr, FSL_DMA_MR_BWC |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 170 | | FSL_DMA_MR_EIE | FSL_DMA_MR_EOLNIE, 32); |
Ira Snyder | e8bd84d | 2011-03-03 07:54:54 +0000 | [diff] [blame] | 171 | break; |
| 172 | case FSL_DMA_IP_83XX: |
| 173 | /* Set the channel to below modes: |
| 174 | * EOTIE - End-of-transfer interrupt enable |
| 175 | * PRC_RM - PCI read multiple |
| 176 | */ |
| 177 | DMA_OUT(chan, &chan->regs->mr, FSL_DMA_MR_EOTIE |
| 178 | | FSL_DMA_MR_PRC_RM, 32); |
| 179 | break; |
| 180 | } |
Zhang Wei | f79abb6 | 2008-03-18 18:45:00 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 183 | static int dma_is_idle(struct fsldma_chan *chan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 184 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 185 | u32 sr = get_sr(chan); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 186 | return (!(sr & FSL_DMA_SR_CB)) || (sr & FSL_DMA_SR_CH); |
| 187 | } |
| 188 | |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 189 | /* |
| 190 | * Start the DMA controller |
| 191 | * |
| 192 | * Preconditions: |
| 193 | * - the CDAR register must point to the start descriptor |
| 194 | * - the MRn[CS] bit must be cleared |
| 195 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 196 | static void dma_start(struct fsldma_chan *chan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 197 | { |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 198 | u32 mode; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 199 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 200 | mode = DMA_IN(chan, &chan->regs->mr, 32); |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 201 | |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 202 | if (chan->feature & FSL_DMA_CHAN_PAUSE_EXT) { |
| 203 | DMA_OUT(chan, &chan->regs->bcr, 0, 32); |
| 204 | mode |= FSL_DMA_MR_EMP_EN; |
| 205 | } else { |
| 206 | mode &= ~FSL_DMA_MR_EMP_EN; |
Ira Snyder | 43a1a3e | 2009-05-28 09:26:40 +0000 | [diff] [blame] | 207 | } |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 208 | |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 209 | if (chan->feature & FSL_DMA_CHAN_START_EXT) { |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 210 | mode |= FSL_DMA_MR_EMS_EN; |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 211 | } else { |
| 212 | mode &= ~FSL_DMA_MR_EMS_EN; |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 213 | mode |= FSL_DMA_MR_CS; |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 214 | } |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 215 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 216 | DMA_OUT(chan, &chan->regs->mr, mode, 32); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 219 | static void dma_halt(struct fsldma_chan *chan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 220 | { |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 221 | u32 mode; |
Dan Williams | 900325a6 | 2009-03-02 15:33:46 -0700 | [diff] [blame] | 222 | int i; |
| 223 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 224 | mode = DMA_IN(chan, &chan->regs->mr, 32); |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 225 | mode |= FSL_DMA_MR_CA; |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 226 | DMA_OUT(chan, &chan->regs->mr, mode, 32); |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 227 | |
| 228 | mode &= ~(FSL_DMA_MR_CS | FSL_DMA_MR_EMS_EN | FSL_DMA_MR_CA); |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 229 | DMA_OUT(chan, &chan->regs->mr, mode, 32); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 230 | |
Dan Williams | 900325a6 | 2009-03-02 15:33:46 -0700 | [diff] [blame] | 231 | for (i = 0; i < 100; i++) { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 232 | if (dma_is_idle(chan)) |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 233 | return; |
| 234 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 235 | udelay(10); |
Dan Williams | 900325a6 | 2009-03-02 15:33:46 -0700 | [diff] [blame] | 236 | } |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 237 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 238 | if (!dma_is_idle(chan)) |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 239 | chan_err(chan, "DMA halt timeout!\n"); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 242 | /** |
| 243 | * fsl_chan_set_src_loop_size - Set source address hold transfer size |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 244 | * @chan : Freescale DMA channel |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 245 | * @size : Address loop size, 0 for disable loop |
| 246 | * |
| 247 | * The set source address hold transfer size. The source |
| 248 | * address hold or loop transfer size is when the DMA transfer |
| 249 | * data from source address (SA), if the loop size is 4, the DMA will |
| 250 | * read data from SA, SA + 1, SA + 2, SA + 3, then loop back to SA, |
| 251 | * SA + 1 ... and so on. |
| 252 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 253 | static void fsl_chan_set_src_loop_size(struct fsldma_chan *chan, int size) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 254 | { |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 255 | u32 mode; |
| 256 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 257 | mode = DMA_IN(chan, &chan->regs->mr, 32); |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 258 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 259 | switch (size) { |
| 260 | case 0: |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 261 | mode &= ~FSL_DMA_MR_SAHE; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 262 | break; |
| 263 | case 1: |
| 264 | case 2: |
| 265 | case 4: |
| 266 | case 8: |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 267 | mode |= FSL_DMA_MR_SAHE | (__ilog2(size) << 14); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 268 | break; |
| 269 | } |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 270 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 271 | DMA_OUT(chan, &chan->regs->mr, mode, 32); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /** |
Ira Snyder | 738f5f7 | 2010-01-06 13:34:02 +0000 | [diff] [blame] | 275 | * fsl_chan_set_dst_loop_size - Set destination address hold transfer size |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 276 | * @chan : Freescale DMA channel |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 277 | * @size : Address loop size, 0 for disable loop |
| 278 | * |
| 279 | * The set destination address hold transfer size. The destination |
| 280 | * address hold or loop transfer size is when the DMA transfer |
| 281 | * data to destination address (TA), if the loop size is 4, the DMA will |
| 282 | * write data to TA, TA + 1, TA + 2, TA + 3, then loop back to TA, |
| 283 | * TA + 1 ... and so on. |
| 284 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 285 | static void fsl_chan_set_dst_loop_size(struct fsldma_chan *chan, int size) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 286 | { |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 287 | u32 mode; |
| 288 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 289 | mode = DMA_IN(chan, &chan->regs->mr, 32); |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 290 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 291 | switch (size) { |
| 292 | case 0: |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 293 | mode &= ~FSL_DMA_MR_DAHE; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 294 | break; |
| 295 | case 1: |
| 296 | case 2: |
| 297 | case 4: |
| 298 | case 8: |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 299 | mode |= FSL_DMA_MR_DAHE | (__ilog2(size) << 16); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 300 | break; |
| 301 | } |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 302 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 303 | DMA_OUT(chan, &chan->regs->mr, mode, 32); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /** |
Ira Snyder | e6c7ecb | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 307 | * fsl_chan_set_request_count - Set DMA Request Count for external control |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 308 | * @chan : Freescale DMA channel |
Ira Snyder | e6c7ecb | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 309 | * @size : Number of bytes to transfer in a single request |
| 310 | * |
| 311 | * The Freescale DMA channel can be controlled by the external signal DREQ#. |
| 312 | * The DMA request count is how many bytes are allowed to transfer before |
| 313 | * pausing the channel, after which a new assertion of DREQ# resumes channel |
| 314 | * operation. |
| 315 | * |
| 316 | * A size of 0 disables external pause control. The maximum size is 1024. |
| 317 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 318 | static void fsl_chan_set_request_count(struct fsldma_chan *chan, int size) |
Ira Snyder | e6c7ecb | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 319 | { |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 320 | u32 mode; |
| 321 | |
Ira Snyder | e6c7ecb | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 322 | BUG_ON(size > 1024); |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 323 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 324 | mode = DMA_IN(chan, &chan->regs->mr, 32); |
Ira Snyder | 272ca65 | 2010-01-06 13:33:59 +0000 | [diff] [blame] | 325 | mode |= (__ilog2(size) << 24) & 0x0f000000; |
| 326 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 327 | DMA_OUT(chan, &chan->regs->mr, mode, 32); |
Ira Snyder | e6c7ecb | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /** |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 331 | * fsl_chan_toggle_ext_pause - Toggle channel external pause status |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 332 | * @chan : Freescale DMA channel |
Ira Snyder | e6c7ecb | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 333 | * @enable : 0 is disabled, 1 is enabled. |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 334 | * |
Ira Snyder | e6c7ecb | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 335 | * The Freescale DMA channel can be controlled by the external signal DREQ#. |
| 336 | * The DMA Request Count feature should be used in addition to this feature |
| 337 | * to set the number of bytes to transfer before pausing the channel. |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 338 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 339 | static void fsl_chan_toggle_ext_pause(struct fsldma_chan *chan, int enable) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 340 | { |
Ira Snyder | e6c7ecb | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 341 | if (enable) |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 342 | chan->feature |= FSL_DMA_CHAN_PAUSE_EXT; |
Ira Snyder | e6c7ecb | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 343 | else |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 344 | chan->feature &= ~FSL_DMA_CHAN_PAUSE_EXT; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | /** |
| 348 | * fsl_chan_toggle_ext_start - Toggle channel external start status |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 349 | * @chan : Freescale DMA channel |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 350 | * @enable : 0 is disabled, 1 is enabled. |
| 351 | * |
| 352 | * If enable the external start, the channel can be started by an |
| 353 | * external DMA start pin. So the dma_start() does not start the |
| 354 | * transfer immediately. The DMA channel will wait for the |
| 355 | * control pin asserted. |
| 356 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 357 | static void fsl_chan_toggle_ext_start(struct fsldma_chan *chan, int enable) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 358 | { |
| 359 | if (enable) |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 360 | chan->feature |= FSL_DMA_CHAN_START_EXT; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 361 | else |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 362 | chan->feature &= ~FSL_DMA_CHAN_START_EXT; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Ira Snyder | 31f4306 | 2011-03-03 07:54:57 +0000 | [diff] [blame] | 365 | static void append_ld_queue(struct fsldma_chan *chan, struct fsl_desc_sw *desc) |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 366 | { |
| 367 | struct fsl_desc_sw *tail = to_fsl_desc(chan->ld_pending.prev); |
| 368 | |
| 369 | if (list_empty(&chan->ld_pending)) |
| 370 | goto out_splice; |
| 371 | |
| 372 | /* |
| 373 | * Add the hardware descriptor to the chain of hardware descriptors |
| 374 | * that already exists in memory. |
| 375 | * |
| 376 | * This will un-set the EOL bit of the existing transaction, and the |
| 377 | * last link in this transaction will become the EOL descriptor. |
| 378 | */ |
| 379 | set_desc_next(chan, &tail->hw, desc->async_tx.phys); |
| 380 | |
| 381 | /* |
| 382 | * Add the software descriptor and all children to the list |
| 383 | * of pending transactions |
| 384 | */ |
| 385 | out_splice: |
| 386 | list_splice_tail_init(&desc->tx_list, &chan->ld_pending); |
| 387 | } |
| 388 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 389 | static dma_cookie_t fsl_dma_tx_submit(struct dma_async_tx_descriptor *tx) |
| 390 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 391 | struct fsldma_chan *chan = to_fsl_chan(tx->chan); |
Dan Williams | eda3423 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 392 | struct fsl_desc_sw *desc = tx_to_fsl_desc(tx); |
| 393 | struct fsl_desc_sw *child; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 394 | unsigned long flags; |
| 395 | dma_cookie_t cookie; |
| 396 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 397 | spin_lock_irqsave(&chan->desc_lock, flags); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 398 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 399 | /* |
| 400 | * assign cookies to all of the software descriptors |
| 401 | * that make up this transaction |
| 402 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 403 | cookie = chan->common.cookie; |
Dan Williams | eda3423 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 404 | list_for_each_entry(child, &desc->tx_list, node) { |
Ira Snyder | bcfb746 | 2009-05-15 14:27:16 -0700 | [diff] [blame] | 405 | cookie++; |
Ira Snyder | 31f4306 | 2011-03-03 07:54:57 +0000 | [diff] [blame] | 406 | if (cookie < DMA_MIN_COOKIE) |
| 407 | cookie = DMA_MIN_COOKIE; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 408 | |
Steven J. Magnani | 6ca3a7a | 2010-02-25 13:39:30 -0600 | [diff] [blame] | 409 | child->async_tx.cookie = cookie; |
Ira Snyder | bcfb746 | 2009-05-15 14:27:16 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 412 | chan->common.cookie = cookie; |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 413 | |
| 414 | /* put this transaction onto the tail of the pending queue */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 415 | append_ld_queue(chan, desc); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 416 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 417 | spin_unlock_irqrestore(&chan->desc_lock, flags); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 418 | |
| 419 | return cookie; |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * fsl_dma_alloc_descriptor - Allocate descriptor from channel's DMA pool. |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 424 | * @chan : Freescale DMA channel |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 425 | * |
| 426 | * Return - The descriptor allocated. NULL for failed. |
| 427 | */ |
Ira Snyder | 31f4306 | 2011-03-03 07:54:57 +0000 | [diff] [blame] | 428 | static struct fsl_desc_sw *fsl_dma_alloc_descriptor(struct fsldma_chan *chan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 429 | { |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 430 | struct fsl_desc_sw *desc; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 431 | dma_addr_t pdesc; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 432 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 433 | desc = dma_pool_alloc(chan->desc_pool, GFP_ATOMIC, &pdesc); |
| 434 | if (!desc) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 435 | chan_dbg(chan, "out of memory for link descriptor\n"); |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 436 | return NULL; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 439 | memset(desc, 0, sizeof(*desc)); |
| 440 | INIT_LIST_HEAD(&desc->tx_list); |
| 441 | dma_async_tx_descriptor_init(&desc->async_tx, &chan->common); |
| 442 | desc->async_tx.tx_submit = fsl_dma_tx_submit; |
| 443 | desc->async_tx.phys = pdesc; |
| 444 | |
Ira Snyder | 0ab09c3 | 2011-03-03 07:54:56 +0000 | [diff] [blame] | 445 | #ifdef FSL_DMA_LD_DEBUG |
| 446 | chan_dbg(chan, "LD %p allocated\n", desc); |
| 447 | #endif |
| 448 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 449 | return desc; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 452 | /** |
| 453 | * fsl_dma_alloc_chan_resources - Allocate resources for DMA channel. |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 454 | * @chan : Freescale DMA channel |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 455 | * |
| 456 | * This function will create a dma pool for descriptor allocation. |
| 457 | * |
| 458 | * Return - The number of descriptors allocated. |
| 459 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 460 | static int fsl_dma_alloc_chan_resources(struct dma_chan *dchan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 461 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 462 | struct fsldma_chan *chan = to_fsl_chan(dchan); |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 463 | |
| 464 | /* Has this channel already been allocated? */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 465 | if (chan->desc_pool) |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 466 | return 1; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 467 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 468 | /* |
| 469 | * We need the descriptor to be aligned to 32bytes |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 470 | * for meeting FSL DMA specification requirement. |
| 471 | */ |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 472 | chan->desc_pool = dma_pool_create(chan->name, chan->dev, |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 473 | sizeof(struct fsl_desc_sw), |
| 474 | __alignof__(struct fsl_desc_sw), 0); |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 475 | if (!chan->desc_pool) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 476 | chan_err(chan, "unable to allocate descriptor pool\n"); |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 477 | return -ENOMEM; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 480 | /* there is at least one descriptor free to be allocated */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 481 | return 1; |
| 482 | } |
| 483 | |
| 484 | /** |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 485 | * fsldma_free_desc_list - Free all descriptors in a queue |
| 486 | * @chan: Freescae DMA channel |
| 487 | * @list: the list to free |
| 488 | * |
| 489 | * LOCKING: must hold chan->desc_lock |
| 490 | */ |
| 491 | static void fsldma_free_desc_list(struct fsldma_chan *chan, |
| 492 | struct list_head *list) |
| 493 | { |
| 494 | struct fsl_desc_sw *desc, *_desc; |
| 495 | |
| 496 | list_for_each_entry_safe(desc, _desc, list, node) { |
| 497 | list_del(&desc->node); |
Ira Snyder | 0ab09c3 | 2011-03-03 07:54:56 +0000 | [diff] [blame] | 498 | #ifdef FSL_DMA_LD_DEBUG |
| 499 | chan_dbg(chan, "LD %p free\n", desc); |
| 500 | #endif |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 501 | dma_pool_free(chan->desc_pool, desc, desc->async_tx.phys); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | static void fsldma_free_desc_list_reverse(struct fsldma_chan *chan, |
| 506 | struct list_head *list) |
| 507 | { |
| 508 | struct fsl_desc_sw *desc, *_desc; |
| 509 | |
| 510 | list_for_each_entry_safe_reverse(desc, _desc, list, node) { |
| 511 | list_del(&desc->node); |
Ira Snyder | 0ab09c3 | 2011-03-03 07:54:56 +0000 | [diff] [blame] | 512 | #ifdef FSL_DMA_LD_DEBUG |
| 513 | chan_dbg(chan, "LD %p free\n", desc); |
| 514 | #endif |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 515 | dma_pool_free(chan->desc_pool, desc, desc->async_tx.phys); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | /** |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 520 | * fsl_dma_free_chan_resources - Free all resources of the channel. |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 521 | * @chan : Freescale DMA channel |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 522 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 523 | static void fsl_dma_free_chan_resources(struct dma_chan *dchan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 524 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 525 | struct fsldma_chan *chan = to_fsl_chan(dchan); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 526 | unsigned long flags; |
| 527 | |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 528 | chan_dbg(chan, "free all channel resources\n"); |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 529 | spin_lock_irqsave(&chan->desc_lock, flags); |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 530 | fsldma_free_desc_list(chan, &chan->ld_pending); |
| 531 | fsldma_free_desc_list(chan, &chan->ld_running); |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 532 | spin_unlock_irqrestore(&chan->desc_lock, flags); |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 533 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 534 | dma_pool_destroy(chan->desc_pool); |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 535 | chan->desc_pool = NULL; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Zhang Wei | 2187c26 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 538 | static struct dma_async_tx_descriptor * |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 539 | fsl_dma_prep_interrupt(struct dma_chan *dchan, unsigned long flags) |
Zhang Wei | 2187c26 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 540 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 541 | struct fsldma_chan *chan; |
Zhang Wei | 2187c26 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 542 | struct fsl_desc_sw *new; |
| 543 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 544 | if (!dchan) |
Zhang Wei | 2187c26 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 545 | return NULL; |
| 546 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 547 | chan = to_fsl_chan(dchan); |
Zhang Wei | 2187c26 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 548 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 549 | new = fsl_dma_alloc_descriptor(chan); |
Zhang Wei | 2187c26 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 550 | if (!new) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 551 | chan_err(chan, "%s\n", msg_ld_oom); |
Zhang Wei | 2187c26 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 552 | return NULL; |
| 553 | } |
| 554 | |
| 555 | new->async_tx.cookie = -EBUSY; |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 556 | new->async_tx.flags = flags; |
Zhang Wei | 2187c26 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 557 | |
Zhang Wei | f79abb6 | 2008-03-18 18:45:00 -0700 | [diff] [blame] | 558 | /* Insert the link descriptor to the LD ring */ |
Dan Williams | eda3423 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 559 | list_add_tail(&new->node, &new->tx_list); |
Zhang Wei | f79abb6 | 2008-03-18 18:45:00 -0700 | [diff] [blame] | 560 | |
Ira Snyder | 31f4306 | 2011-03-03 07:54:57 +0000 | [diff] [blame] | 561 | /* Set End-of-link to the last link descriptor of new list */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 562 | set_ld_eol(chan, new); |
Zhang Wei | 2187c26 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 563 | |
| 564 | return &new->async_tx; |
| 565 | } |
| 566 | |
Ira Snyder | 31f4306 | 2011-03-03 07:54:57 +0000 | [diff] [blame] | 567 | static struct dma_async_tx_descriptor * |
| 568 | fsl_dma_prep_memcpy(struct dma_chan *dchan, |
| 569 | dma_addr_t dma_dst, dma_addr_t dma_src, |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 570 | size_t len, unsigned long flags) |
| 571 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 572 | struct fsldma_chan *chan; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 573 | struct fsl_desc_sw *first = NULL, *prev = NULL, *new; |
| 574 | size_t copy; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 575 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 576 | if (!dchan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 577 | return NULL; |
| 578 | |
| 579 | if (!len) |
| 580 | return NULL; |
| 581 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 582 | chan = to_fsl_chan(dchan); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 583 | |
| 584 | do { |
| 585 | |
| 586 | /* Allocate the link descriptor from DMA pool */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 587 | new = fsl_dma_alloc_descriptor(chan); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 588 | if (!new) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 589 | chan_err(chan, "%s\n", msg_ld_oom); |
Ira Snyder | 2e077f8 | 2009-05-15 09:59:46 -0700 | [diff] [blame] | 590 | goto fail; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 591 | } |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 592 | |
Zhang Wei | 5682284 | 2008-03-13 10:45:27 -0700 | [diff] [blame] | 593 | copy = min(len, (size_t)FSL_DMA_BCR_MAX_CNT); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 594 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 595 | set_desc_cnt(chan, &new->hw, copy); |
| 596 | set_desc_src(chan, &new->hw, dma_src); |
| 597 | set_desc_dst(chan, &new->hw, dma_dst); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 598 | |
| 599 | if (!first) |
| 600 | first = new; |
| 601 | else |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 602 | set_desc_next(chan, &prev->hw, new->async_tx.phys); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 603 | |
| 604 | new->async_tx.cookie = 0; |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 605 | async_tx_ack(&new->async_tx); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 606 | |
| 607 | prev = new; |
| 608 | len -= copy; |
| 609 | dma_src += copy; |
Ira Snyder | 738f5f7 | 2010-01-06 13:34:02 +0000 | [diff] [blame] | 610 | dma_dst += copy; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 611 | |
| 612 | /* Insert the link descriptor to the LD ring */ |
Dan Williams | eda3423 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 613 | list_add_tail(&new->node, &first->tx_list); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 614 | } while (len); |
| 615 | |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 616 | new->async_tx.flags = flags; /* client is in control of this ack */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 617 | new->async_tx.cookie = -EBUSY; |
| 618 | |
Ira Snyder | 31f4306 | 2011-03-03 07:54:57 +0000 | [diff] [blame] | 619 | /* Set End-of-link to the last link descriptor of new list */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 620 | set_ld_eol(chan, new); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 621 | |
Ira Snyder | 2e077f8 | 2009-05-15 09:59:46 -0700 | [diff] [blame] | 622 | return &first->async_tx; |
| 623 | |
| 624 | fail: |
| 625 | if (!first) |
| 626 | return NULL; |
| 627 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 628 | fsldma_free_desc_list_reverse(chan, &first->tx_list); |
Ira Snyder | 2e077f8 | 2009-05-15 09:59:46 -0700 | [diff] [blame] | 629 | return NULL; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Ira Snyder | c1433041 | 2010-09-30 11:46:45 +0000 | [diff] [blame] | 632 | static struct dma_async_tx_descriptor *fsl_dma_prep_sg(struct dma_chan *dchan, |
| 633 | struct scatterlist *dst_sg, unsigned int dst_nents, |
| 634 | struct scatterlist *src_sg, unsigned int src_nents, |
| 635 | unsigned long flags) |
| 636 | { |
| 637 | struct fsl_desc_sw *first = NULL, *prev = NULL, *new = NULL; |
| 638 | struct fsldma_chan *chan = to_fsl_chan(dchan); |
| 639 | size_t dst_avail, src_avail; |
| 640 | dma_addr_t dst, src; |
| 641 | size_t len; |
| 642 | |
| 643 | /* basic sanity checks */ |
| 644 | if (dst_nents == 0 || src_nents == 0) |
| 645 | return NULL; |
| 646 | |
| 647 | if (dst_sg == NULL || src_sg == NULL) |
| 648 | return NULL; |
| 649 | |
| 650 | /* |
| 651 | * TODO: should we check that both scatterlists have the same |
| 652 | * TODO: number of bytes in total? Is that really an error? |
| 653 | */ |
| 654 | |
| 655 | /* get prepared for the loop */ |
| 656 | dst_avail = sg_dma_len(dst_sg); |
| 657 | src_avail = sg_dma_len(src_sg); |
| 658 | |
| 659 | /* run until we are out of scatterlist entries */ |
| 660 | while (true) { |
| 661 | |
| 662 | /* create the largest transaction possible */ |
| 663 | len = min_t(size_t, src_avail, dst_avail); |
| 664 | len = min_t(size_t, len, FSL_DMA_BCR_MAX_CNT); |
| 665 | if (len == 0) |
| 666 | goto fetch; |
| 667 | |
| 668 | dst = sg_dma_address(dst_sg) + sg_dma_len(dst_sg) - dst_avail; |
| 669 | src = sg_dma_address(src_sg) + sg_dma_len(src_sg) - src_avail; |
| 670 | |
| 671 | /* allocate and populate the descriptor */ |
| 672 | new = fsl_dma_alloc_descriptor(chan); |
| 673 | if (!new) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 674 | chan_err(chan, "%s\n", msg_ld_oom); |
Ira Snyder | c1433041 | 2010-09-30 11:46:45 +0000 | [diff] [blame] | 675 | goto fail; |
| 676 | } |
Ira Snyder | c1433041 | 2010-09-30 11:46:45 +0000 | [diff] [blame] | 677 | |
| 678 | set_desc_cnt(chan, &new->hw, len); |
| 679 | set_desc_src(chan, &new->hw, src); |
| 680 | set_desc_dst(chan, &new->hw, dst); |
| 681 | |
| 682 | if (!first) |
| 683 | first = new; |
| 684 | else |
| 685 | set_desc_next(chan, &prev->hw, new->async_tx.phys); |
| 686 | |
| 687 | new->async_tx.cookie = 0; |
| 688 | async_tx_ack(&new->async_tx); |
| 689 | prev = new; |
| 690 | |
| 691 | /* Insert the link descriptor to the LD ring */ |
| 692 | list_add_tail(&new->node, &first->tx_list); |
| 693 | |
| 694 | /* update metadata */ |
| 695 | dst_avail -= len; |
| 696 | src_avail -= len; |
| 697 | |
| 698 | fetch: |
| 699 | /* fetch the next dst scatterlist entry */ |
| 700 | if (dst_avail == 0) { |
| 701 | |
| 702 | /* no more entries: we're done */ |
| 703 | if (dst_nents == 0) |
| 704 | break; |
| 705 | |
| 706 | /* fetch the next entry: if there are no more: done */ |
| 707 | dst_sg = sg_next(dst_sg); |
| 708 | if (dst_sg == NULL) |
| 709 | break; |
| 710 | |
| 711 | dst_nents--; |
| 712 | dst_avail = sg_dma_len(dst_sg); |
| 713 | } |
| 714 | |
| 715 | /* fetch the next src scatterlist entry */ |
| 716 | if (src_avail == 0) { |
| 717 | |
| 718 | /* no more entries: we're done */ |
| 719 | if (src_nents == 0) |
| 720 | break; |
| 721 | |
| 722 | /* fetch the next entry: if there are no more: done */ |
| 723 | src_sg = sg_next(src_sg); |
| 724 | if (src_sg == NULL) |
| 725 | break; |
| 726 | |
| 727 | src_nents--; |
| 728 | src_avail = sg_dma_len(src_sg); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | new->async_tx.flags = flags; /* client is in control of this ack */ |
| 733 | new->async_tx.cookie = -EBUSY; |
| 734 | |
| 735 | /* Set End-of-link to the last link descriptor of new list */ |
| 736 | set_ld_eol(chan, new); |
| 737 | |
| 738 | return &first->async_tx; |
| 739 | |
| 740 | fail: |
| 741 | if (!first) |
| 742 | return NULL; |
| 743 | |
| 744 | fsldma_free_desc_list_reverse(chan, &first->tx_list); |
| 745 | return NULL; |
| 746 | } |
| 747 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 748 | /** |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 749 | * fsl_dma_prep_slave_sg - prepare descriptors for a DMA_SLAVE transaction |
| 750 | * @chan: DMA channel |
| 751 | * @sgl: scatterlist to transfer to/from |
| 752 | * @sg_len: number of entries in @scatterlist |
| 753 | * @direction: DMA direction |
| 754 | * @flags: DMAEngine flags |
| 755 | * |
| 756 | * Prepare a set of descriptors for a DMA_SLAVE transaction. Following the |
| 757 | * DMA_SLAVE API, this gets the device-specific information from the |
| 758 | * chan->private variable. |
| 759 | */ |
| 760 | static struct dma_async_tx_descriptor *fsl_dma_prep_slave_sg( |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 761 | struct dma_chan *dchan, struct scatterlist *sgl, unsigned int sg_len, |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 762 | enum dma_data_direction direction, unsigned long flags) |
| 763 | { |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 764 | /* |
Ira Snyder | 968f19a | 2010-09-30 11:46:46 +0000 | [diff] [blame] | 765 | * This operation is not supported on the Freescale DMA controller |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 766 | * |
Ira Snyder | 968f19a | 2010-09-30 11:46:46 +0000 | [diff] [blame] | 767 | * However, we need to provide the function pointer to allow the |
| 768 | * device_control() method to work. |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 769 | */ |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 770 | return NULL; |
| 771 | } |
| 772 | |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 773 | static int fsl_dma_device_control(struct dma_chan *dchan, |
Linus Walleij | 0582763 | 2010-05-17 16:30:42 -0700 | [diff] [blame] | 774 | enum dma_ctrl_cmd cmd, unsigned long arg) |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 775 | { |
Ira Snyder | 968f19a | 2010-09-30 11:46:46 +0000 | [diff] [blame] | 776 | struct dma_slave_config *config; |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 777 | struct fsldma_chan *chan; |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 778 | unsigned long flags; |
Ira Snyder | 968f19a | 2010-09-30 11:46:46 +0000 | [diff] [blame] | 779 | int size; |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 780 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 781 | if (!dchan) |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 782 | return -EINVAL; |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 783 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 784 | chan = to_fsl_chan(dchan); |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 785 | |
Ira Snyder | 968f19a | 2010-09-30 11:46:46 +0000 | [diff] [blame] | 786 | switch (cmd) { |
| 787 | case DMA_TERMINATE_ALL: |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 788 | spin_lock_irqsave(&chan->desc_lock, flags); |
| 789 | |
Ira Snyder | 968f19a | 2010-09-30 11:46:46 +0000 | [diff] [blame] | 790 | /* Halt the DMA engine */ |
| 791 | dma_halt(chan); |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 792 | |
Ira Snyder | 968f19a | 2010-09-30 11:46:46 +0000 | [diff] [blame] | 793 | /* Remove and free all of the descriptors in the LD queue */ |
| 794 | fsldma_free_desc_list(chan, &chan->ld_pending); |
| 795 | fsldma_free_desc_list(chan, &chan->ld_running); |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 796 | chan->idle = true; |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 797 | |
Ira Snyder | 968f19a | 2010-09-30 11:46:46 +0000 | [diff] [blame] | 798 | spin_unlock_irqrestore(&chan->desc_lock, flags); |
| 799 | return 0; |
| 800 | |
| 801 | case DMA_SLAVE_CONFIG: |
| 802 | config = (struct dma_slave_config *)arg; |
| 803 | |
| 804 | /* make sure the channel supports setting burst size */ |
| 805 | if (!chan->set_request_count) |
| 806 | return -ENXIO; |
| 807 | |
| 808 | /* we set the controller burst size depending on direction */ |
| 809 | if (config->direction == DMA_TO_DEVICE) |
| 810 | size = config->dst_addr_width * config->dst_maxburst; |
| 811 | else |
| 812 | size = config->src_addr_width * config->src_maxburst; |
| 813 | |
| 814 | chan->set_request_count(chan, size); |
| 815 | return 0; |
| 816 | |
| 817 | case FSLDMA_EXTERNAL_START: |
| 818 | |
| 819 | /* make sure the channel supports external start */ |
| 820 | if (!chan->toggle_ext_start) |
| 821 | return -ENXIO; |
| 822 | |
| 823 | chan->toggle_ext_start(chan, arg); |
| 824 | return 0; |
| 825 | |
| 826 | default: |
| 827 | return -ENXIO; |
| 828 | } |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 829 | |
| 830 | return 0; |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /** |
Ira Snyder | 9c4d1e7 | 2011-03-03 07:54:59 +0000 | [diff] [blame^] | 834 | * fsldma_cleanup_descriptor - cleanup and free a single link descriptor |
| 835 | * @chan: Freescale DMA channel |
| 836 | * @desc: descriptor to cleanup and free |
| 837 | * |
| 838 | * This function is used on a descriptor which has been executed by the DMA |
| 839 | * controller. It will run any callbacks, submit any dependencies, and then |
| 840 | * free the descriptor. |
| 841 | */ |
| 842 | static void fsldma_cleanup_descriptor(struct fsldma_chan *chan, |
| 843 | struct fsl_desc_sw *desc) |
| 844 | { |
| 845 | struct dma_async_tx_descriptor *txd = &desc->async_tx; |
| 846 | struct device *dev = chan->common.device->dev; |
| 847 | dma_addr_t src = get_desc_src(chan, desc); |
| 848 | dma_addr_t dst = get_desc_dst(chan, desc); |
| 849 | u32 len = get_desc_cnt(chan, desc); |
| 850 | |
| 851 | /* Run the link descriptor callback function */ |
| 852 | if (txd->callback) { |
| 853 | #ifdef FSL_DMA_LD_DEBUG |
| 854 | chan_dbg(chan, "LD %p callback\n", desc); |
| 855 | #endif |
| 856 | txd->callback(txd->callback_param); |
| 857 | } |
| 858 | |
| 859 | /* Run any dependencies */ |
| 860 | dma_run_dependencies(txd); |
| 861 | |
| 862 | /* Unmap the dst buffer, if requested */ |
| 863 | if (!(txd->flags & DMA_COMPL_SKIP_DEST_UNMAP)) { |
| 864 | if (txd->flags & DMA_COMPL_DEST_UNMAP_SINGLE) |
| 865 | dma_unmap_single(dev, dst, len, DMA_FROM_DEVICE); |
| 866 | else |
| 867 | dma_unmap_page(dev, dst, len, DMA_FROM_DEVICE); |
| 868 | } |
| 869 | |
| 870 | /* Unmap the src buffer, if requested */ |
| 871 | if (!(txd->flags & DMA_COMPL_SKIP_SRC_UNMAP)) { |
| 872 | if (txd->flags & DMA_COMPL_SRC_UNMAP_SINGLE) |
| 873 | dma_unmap_single(dev, src, len, DMA_TO_DEVICE); |
| 874 | else |
| 875 | dma_unmap_page(dev, src, len, DMA_TO_DEVICE); |
| 876 | } |
| 877 | |
| 878 | #ifdef FSL_DMA_LD_DEBUG |
| 879 | chan_dbg(chan, "LD %p free\n", desc); |
| 880 | #endif |
| 881 | dma_pool_free(chan->desc_pool, desc, txd->phys); |
| 882 | } |
| 883 | |
| 884 | /** |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 885 | * fsl_chan_ld_cleanup - Clean up link descriptors |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 886 | * @chan : Freescale DMA channel |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 887 | * |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 888 | * This function is run after the queue of running descriptors has been |
| 889 | * executed by the DMA engine. It will run any callbacks, and then free |
| 890 | * the descriptors. |
| 891 | * |
| 892 | * HARDWARE STATE: idle |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 893 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 894 | static void fsl_chan_ld_cleanup(struct fsldma_chan *chan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 895 | { |
| 896 | struct fsl_desc_sw *desc, *_desc; |
Ira Snyder | 9c4d1e7 | 2011-03-03 07:54:59 +0000 | [diff] [blame^] | 897 | LIST_HEAD(ld_cleanup); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 898 | unsigned long flags; |
| 899 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 900 | spin_lock_irqsave(&chan->desc_lock, flags); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 901 | |
Ira Snyder | 9c4d1e7 | 2011-03-03 07:54:59 +0000 | [diff] [blame^] | 902 | /* update the cookie if we have some descriptors to cleanup */ |
| 903 | if (!list_empty(&chan->ld_running)) { |
| 904 | dma_cookie_t cookie; |
| 905 | |
| 906 | desc = to_fsl_desc(chan->ld_running.prev); |
| 907 | cookie = desc->async_tx.cookie; |
| 908 | |
| 909 | chan->completed_cookie = cookie; |
| 910 | chan_dbg(chan, "completed cookie=%d\n", cookie); |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /* |
Ira Snyder | 9c4d1e7 | 2011-03-03 07:54:59 +0000 | [diff] [blame^] | 914 | * move the descriptors to a temporary list so we can drop the lock |
| 915 | * during the entire cleanup operation |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 916 | */ |
Ira Snyder | 9c4d1e7 | 2011-03-03 07:54:59 +0000 | [diff] [blame^] | 917 | list_splice_tail_init(&chan->ld_running, &ld_cleanup); |
| 918 | |
| 919 | spin_unlock_irqrestore(&chan->desc_lock, flags); |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 920 | |
| 921 | /* Run the callback for each descriptor, in order */ |
Ira Snyder | 9c4d1e7 | 2011-03-03 07:54:59 +0000 | [diff] [blame^] | 922 | list_for_each_entry_safe(desc, _desc, &ld_cleanup, node) { |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 923 | |
Ira Snyder | 9c4d1e7 | 2011-03-03 07:54:59 +0000 | [diff] [blame^] | 924 | /* Remove from the list of transactions */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 925 | list_del(&desc->node); |
| 926 | |
Ira Snyder | 9c4d1e7 | 2011-03-03 07:54:59 +0000 | [diff] [blame^] | 927 | /* Run all cleanup for this descriptor */ |
| 928 | fsldma_cleanup_descriptor(chan, desc); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 929 | } |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | /** |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 933 | * fsl_chan_xfer_ld_queue - transfer any pending transactions |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 934 | * @chan : Freescale DMA channel |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 935 | * |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 936 | * HARDWARE STATE: idle |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 937 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 938 | static void fsl_chan_xfer_ld_queue(struct fsldma_chan *chan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 939 | { |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 940 | struct fsl_desc_sw *desc; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 941 | unsigned long flags; |
| 942 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 943 | spin_lock_irqsave(&chan->desc_lock, flags); |
Ira Snyder | 138ef01 | 2009-05-19 15:42:13 -0700 | [diff] [blame] | 944 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 945 | /* |
| 946 | * If the list of pending descriptors is empty, then we |
| 947 | * don't need to do any work at all |
| 948 | */ |
| 949 | if (list_empty(&chan->ld_pending)) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 950 | chan_dbg(chan, "no pending LDs\n"); |
Ira Snyder | 138ef01 | 2009-05-19 15:42:13 -0700 | [diff] [blame] | 951 | goto out_unlock; |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 952 | } |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 953 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 954 | /* |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 955 | * The DMA controller is not idle, which means that the interrupt |
| 956 | * handler will start any queued transactions when it runs after |
| 957 | * this transaction finishes |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 958 | */ |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 959 | if (!chan->idle) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 960 | chan_dbg(chan, "DMA controller still busy\n"); |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 961 | goto out_unlock; |
| 962 | } |
| 963 | |
| 964 | /* |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 965 | * If there are some link descriptors which have not been |
| 966 | * transferred, we need to start the controller |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 967 | */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 968 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 969 | /* |
| 970 | * Move all elements from the queue of pending transactions |
| 971 | * onto the list of running transactions |
| 972 | */ |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 973 | chan_dbg(chan, "idle, starting controller\n"); |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 974 | desc = list_first_entry(&chan->ld_pending, struct fsl_desc_sw, node); |
| 975 | list_splice_tail_init(&chan->ld_pending, &chan->ld_running); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 976 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 977 | /* |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 978 | * The 85xx DMA controller doesn't clear the channel start bit |
| 979 | * automatically at the end of a transfer. Therefore we must clear |
| 980 | * it in software before starting the transfer. |
| 981 | */ |
| 982 | if ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) { |
| 983 | u32 mode; |
| 984 | |
| 985 | mode = DMA_IN(chan, &chan->regs->mr, 32); |
| 986 | mode &= ~FSL_DMA_MR_CS; |
| 987 | DMA_OUT(chan, &chan->regs->mr, mode, 32); |
| 988 | } |
| 989 | |
| 990 | /* |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 991 | * Program the descriptor's address into the DMA controller, |
| 992 | * then start the DMA transaction |
| 993 | */ |
| 994 | set_cdar(chan, desc->async_tx.phys); |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 995 | get_cdar(chan); |
| 996 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 997 | dma_start(chan); |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 998 | chan->idle = false; |
Ira Snyder | 138ef01 | 2009-05-19 15:42:13 -0700 | [diff] [blame] | 999 | |
| 1000 | out_unlock: |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1001 | spin_unlock_irqrestore(&chan->desc_lock, flags); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | /** |
| 1005 | * fsl_dma_memcpy_issue_pending - Issue the DMA start command |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1006 | * @chan : Freescale DMA channel |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1007 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1008 | static void fsl_dma_memcpy_issue_pending(struct dma_chan *dchan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1009 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1010 | struct fsldma_chan *chan = to_fsl_chan(dchan); |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1011 | fsl_chan_xfer_ld_queue(chan); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1014 | /** |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1015 | * fsl_tx_status - Determine the DMA status |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1016 | * @chan : Freescale DMA channel |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1017 | */ |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1018 | static enum dma_status fsl_tx_status(struct dma_chan *dchan, |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1019 | dma_cookie_t cookie, |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1020 | struct dma_tx_state *txstate) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1021 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1022 | struct fsldma_chan *chan = to_fsl_chan(dchan); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1023 | dma_cookie_t last_complete; |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 1024 | dma_cookie_t last_used; |
| 1025 | unsigned long flags; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1026 | |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 1027 | spin_lock_irqsave(&chan->desc_lock, flags); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1028 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1029 | last_complete = chan->completed_cookie; |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 1030 | last_used = dchan->cookie; |
| 1031 | |
| 1032 | spin_unlock_irqrestore(&chan->desc_lock, flags); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1033 | |
Dan Williams | bca3469 | 2010-03-26 16:52:10 -0700 | [diff] [blame] | 1034 | dma_set_tx_state(txstate, last_complete, last_used, 0); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1035 | return dma_async_is_complete(cookie, last_complete, last_used); |
| 1036 | } |
| 1037 | |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1038 | /*----------------------------------------------------------------------------*/ |
| 1039 | /* Interrupt Handling */ |
| 1040 | /*----------------------------------------------------------------------------*/ |
| 1041 | |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1042 | static irqreturn_t fsldma_chan_irq(int irq, void *data) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1043 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1044 | struct fsldma_chan *chan = data; |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1045 | u32 stat; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1046 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 1047 | /* save and clear the status register */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1048 | stat = get_sr(chan); |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 1049 | set_sr(chan, stat); |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 1050 | chan_dbg(chan, "irq: stat = 0x%x\n", stat); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1051 | |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 1052 | /* check that this was really our device */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1053 | stat &= ~(FSL_DMA_SR_CB | FSL_DMA_SR_CH); |
| 1054 | if (!stat) |
| 1055 | return IRQ_NONE; |
| 1056 | |
| 1057 | if (stat & FSL_DMA_SR_TE) |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 1058 | chan_err(chan, "Transfer Error!\n"); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1059 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 1060 | /* |
| 1061 | * Programming Error |
Zhang Wei | f79abb6 | 2008-03-18 18:45:00 -0700 | [diff] [blame] | 1062 | * The DMA_INTERRUPT async_tx is a NULL transfer, which will |
| 1063 | * triger a PE interrupt. |
| 1064 | */ |
| 1065 | if (stat & FSL_DMA_SR_PE) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 1066 | chan_dbg(chan, "irq: Programming Error INT\n"); |
Zhang Wei | f79abb6 | 2008-03-18 18:45:00 -0700 | [diff] [blame] | 1067 | stat &= ~FSL_DMA_SR_PE; |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 1068 | if (get_bcr(chan) != 0) |
| 1069 | chan_err(chan, "Programming Error!\n"); |
Zhang Wei | 1c62979 | 2008-04-17 20:17:25 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 1072 | /* |
| 1073 | * For MPC8349, EOCDI event need to update cookie |
Zhang Wei | 1c62979 | 2008-04-17 20:17:25 -0700 | [diff] [blame] | 1074 | * and start the next transfer if it exist. |
| 1075 | */ |
| 1076 | if (stat & FSL_DMA_SR_EOCDI) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 1077 | chan_dbg(chan, "irq: End-of-Chain link INT\n"); |
Zhang Wei | 1c62979 | 2008-04-17 20:17:25 -0700 | [diff] [blame] | 1078 | stat &= ~FSL_DMA_SR_EOCDI; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 1081 | /* |
| 1082 | * If it current transfer is the end-of-transfer, |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1083 | * we should clear the Channel Start bit for |
| 1084 | * prepare next transfer. |
| 1085 | */ |
Zhang Wei | 1c62979 | 2008-04-17 20:17:25 -0700 | [diff] [blame] | 1086 | if (stat & FSL_DMA_SR_EOLNI) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 1087 | chan_dbg(chan, "irq: End-of-link INT\n"); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1088 | stat &= ~FSL_DMA_SR_EOLNI; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 1091 | /* check that the DMA controller is really idle */ |
| 1092 | if (!dma_is_idle(chan)) |
| 1093 | chan_err(chan, "irq: controller not idle!\n"); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1094 | |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 1095 | /* check that we handled all of the bits */ |
| 1096 | if (stat) |
| 1097 | chan_err(chan, "irq: unhandled sr 0x%08x\n", stat); |
| 1098 | |
| 1099 | /* |
| 1100 | * Schedule the tasklet to handle all cleanup of the current |
| 1101 | * transaction. It will start a new transaction if there is |
| 1102 | * one pending. |
| 1103 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1104 | tasklet_schedule(&chan->tasklet); |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 1105 | chan_dbg(chan, "irq: Exit\n"); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1106 | return IRQ_HANDLED; |
| 1107 | } |
| 1108 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1109 | static void dma_do_tasklet(unsigned long data) |
| 1110 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1111 | struct fsldma_chan *chan = (struct fsldma_chan *)data; |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 1112 | unsigned long flags; |
| 1113 | |
| 1114 | chan_dbg(chan, "tasklet entry\n"); |
| 1115 | |
| 1116 | /* run all callbacks, free all used descriptors */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1117 | fsl_chan_ld_cleanup(chan); |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 1118 | |
| 1119 | /* the channel is now idle */ |
| 1120 | spin_lock_irqsave(&chan->desc_lock, flags); |
| 1121 | chan->idle = true; |
| 1122 | spin_unlock_irqrestore(&chan->desc_lock, flags); |
| 1123 | |
| 1124 | /* start any pending transactions automatically */ |
| 1125 | fsl_chan_xfer_ld_queue(chan); |
| 1126 | chan_dbg(chan, "tasklet exit\n"); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1129 | static irqreturn_t fsldma_ctrl_irq(int irq, void *data) |
| 1130 | { |
| 1131 | struct fsldma_device *fdev = data; |
| 1132 | struct fsldma_chan *chan; |
| 1133 | unsigned int handled = 0; |
| 1134 | u32 gsr, mask; |
| 1135 | int i; |
| 1136 | |
| 1137 | gsr = (fdev->feature & FSL_DMA_BIG_ENDIAN) ? in_be32(fdev->regs) |
| 1138 | : in_le32(fdev->regs); |
| 1139 | mask = 0xff000000; |
| 1140 | dev_dbg(fdev->dev, "IRQ: gsr 0x%.8x\n", gsr); |
| 1141 | |
| 1142 | for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) { |
| 1143 | chan = fdev->chan[i]; |
| 1144 | if (!chan) |
| 1145 | continue; |
| 1146 | |
| 1147 | if (gsr & mask) { |
| 1148 | dev_dbg(fdev->dev, "IRQ: chan %d\n", chan->id); |
| 1149 | fsldma_chan_irq(irq, chan); |
| 1150 | handled++; |
| 1151 | } |
| 1152 | |
| 1153 | gsr &= ~mask; |
| 1154 | mask >>= 8; |
| 1155 | } |
| 1156 | |
| 1157 | return IRQ_RETVAL(handled); |
| 1158 | } |
| 1159 | |
| 1160 | static void fsldma_free_irqs(struct fsldma_device *fdev) |
| 1161 | { |
| 1162 | struct fsldma_chan *chan; |
| 1163 | int i; |
| 1164 | |
| 1165 | if (fdev->irq != NO_IRQ) { |
| 1166 | dev_dbg(fdev->dev, "free per-controller IRQ\n"); |
| 1167 | free_irq(fdev->irq, fdev); |
| 1168 | return; |
| 1169 | } |
| 1170 | |
| 1171 | for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) { |
| 1172 | chan = fdev->chan[i]; |
| 1173 | if (chan && chan->irq != NO_IRQ) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 1174 | chan_dbg(chan, "free per-channel IRQ\n"); |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1175 | free_irq(chan->irq, chan); |
| 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | static int fsldma_request_irqs(struct fsldma_device *fdev) |
| 1181 | { |
| 1182 | struct fsldma_chan *chan; |
| 1183 | int ret; |
| 1184 | int i; |
| 1185 | |
| 1186 | /* if we have a per-controller IRQ, use that */ |
| 1187 | if (fdev->irq != NO_IRQ) { |
| 1188 | dev_dbg(fdev->dev, "request per-controller IRQ\n"); |
| 1189 | ret = request_irq(fdev->irq, fsldma_ctrl_irq, IRQF_SHARED, |
| 1190 | "fsldma-controller", fdev); |
| 1191 | return ret; |
| 1192 | } |
| 1193 | |
| 1194 | /* no per-controller IRQ, use the per-channel IRQs */ |
| 1195 | for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) { |
| 1196 | chan = fdev->chan[i]; |
| 1197 | if (!chan) |
| 1198 | continue; |
| 1199 | |
| 1200 | if (chan->irq == NO_IRQ) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 1201 | chan_err(chan, "interrupts property missing in device tree\n"); |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1202 | ret = -ENODEV; |
| 1203 | goto out_unwind; |
| 1204 | } |
| 1205 | |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 1206 | chan_dbg(chan, "request per-channel IRQ\n"); |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1207 | ret = request_irq(chan->irq, fsldma_chan_irq, IRQF_SHARED, |
| 1208 | "fsldma-chan", chan); |
| 1209 | if (ret) { |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 1210 | chan_err(chan, "unable to request per-channel IRQ\n"); |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1211 | goto out_unwind; |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | return 0; |
| 1216 | |
| 1217 | out_unwind: |
| 1218 | for (/* none */; i >= 0; i--) { |
| 1219 | chan = fdev->chan[i]; |
| 1220 | if (!chan) |
| 1221 | continue; |
| 1222 | |
| 1223 | if (chan->irq == NO_IRQ) |
| 1224 | continue; |
| 1225 | |
| 1226 | free_irq(chan->irq, chan); |
| 1227 | } |
| 1228 | |
| 1229 | return ret; |
| 1230 | } |
| 1231 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 1232 | /*----------------------------------------------------------------------------*/ |
| 1233 | /* OpenFirmware Subsystem */ |
| 1234 | /*----------------------------------------------------------------------------*/ |
| 1235 | |
| 1236 | static int __devinit fsl_dma_chan_probe(struct fsldma_device *fdev, |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1237 | struct device_node *node, u32 feature, const char *compatible) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1238 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1239 | struct fsldma_chan *chan; |
Ira Snyder | 4ce0e95 | 2010-01-06 13:34:00 +0000 | [diff] [blame] | 1240 | struct resource res; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1241 | int err; |
| 1242 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1243 | /* alloc channel */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1244 | chan = kzalloc(sizeof(*chan), GFP_KERNEL); |
| 1245 | if (!chan) { |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1246 | dev_err(fdev->dev, "no free memory for DMA channels!\n"); |
| 1247 | err = -ENOMEM; |
| 1248 | goto out_return; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1251 | /* ioremap registers for use */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1252 | chan->regs = of_iomap(node, 0); |
| 1253 | if (!chan->regs) { |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1254 | dev_err(fdev->dev, "unable to ioremap registers\n"); |
| 1255 | err = -ENOMEM; |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1256 | goto out_free_chan; |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
Ira Snyder | 4ce0e95 | 2010-01-06 13:34:00 +0000 | [diff] [blame] | 1259 | err = of_address_to_resource(node, 0, &res); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1260 | if (err) { |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1261 | dev_err(fdev->dev, "unable to find 'reg' property\n"); |
| 1262 | goto out_iounmap_regs; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1265 | chan->feature = feature; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1266 | if (!fdev->feature) |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1267 | fdev->feature = chan->feature; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1268 | |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1269 | /* |
| 1270 | * If the DMA device's feature is different than the feature |
| 1271 | * of its channels, report the bug |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1272 | */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1273 | WARN_ON(fdev->feature != chan->feature); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1274 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1275 | chan->dev = fdev->dev; |
| 1276 | chan->id = ((res.start - 0x100) & 0xfff) >> 7; |
| 1277 | if (chan->id >= FSL_DMA_MAX_CHANS_PER_DEVICE) { |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1278 | dev_err(fdev->dev, "too many channels for device\n"); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1279 | err = -EINVAL; |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1280 | goto out_iounmap_regs; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1281 | } |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1282 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1283 | fdev->chan[chan->id] = chan; |
| 1284 | tasklet_init(&chan->tasklet, dma_do_tasklet, (unsigned long)chan); |
Ira Snyder | b158471 | 2011-03-03 07:54:55 +0000 | [diff] [blame] | 1285 | snprintf(chan->name, sizeof(chan->name), "chan%d", chan->id); |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1286 | |
| 1287 | /* Initialize the channel */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1288 | dma_init(chan); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1289 | |
| 1290 | /* Clear cdar registers */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1291 | set_cdar(chan, 0); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1292 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1293 | switch (chan->feature & FSL_DMA_IP_MASK) { |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1294 | case FSL_DMA_IP_85XX: |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1295 | chan->toggle_ext_pause = fsl_chan_toggle_ext_pause; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1296 | case FSL_DMA_IP_83XX: |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1297 | chan->toggle_ext_start = fsl_chan_toggle_ext_start; |
| 1298 | chan->set_src_loop_size = fsl_chan_set_src_loop_size; |
| 1299 | chan->set_dst_loop_size = fsl_chan_set_dst_loop_size; |
| 1300 | chan->set_request_count = fsl_chan_set_request_count; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1303 | spin_lock_init(&chan->desc_lock); |
Ira Snyder | 9c3a50b | 2010-01-06 13:34:06 +0000 | [diff] [blame] | 1304 | INIT_LIST_HEAD(&chan->ld_pending); |
| 1305 | INIT_LIST_HEAD(&chan->ld_running); |
Ira Snyder | f04cd40 | 2011-03-03 07:54:58 +0000 | [diff] [blame] | 1306 | chan->idle = true; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1307 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1308 | chan->common.device = &fdev->common; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1309 | |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1310 | /* find the IRQ line, if it exists in the device tree */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1311 | chan->irq = irq_of_parse_and_map(node, 0); |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1312 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1313 | /* Add the channel to DMA device channel list */ |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1314 | list_add_tail(&chan->common.device_node, &fdev->common.channels); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1315 | fdev->common.chancnt++; |
| 1316 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1317 | dev_info(fdev->dev, "#%d (%s), irq %d\n", chan->id, compatible, |
| 1318 | chan->irq != NO_IRQ ? chan->irq : fdev->irq); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1319 | |
| 1320 | return 0; |
Li Yang | 51ee87f | 2008-05-29 23:25:45 -0700 | [diff] [blame] | 1321 | |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1322 | out_iounmap_regs: |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1323 | iounmap(chan->regs); |
| 1324 | out_free_chan: |
| 1325 | kfree(chan); |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1326 | out_return: |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1327 | return err; |
| 1328 | } |
| 1329 | |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1330 | static void fsl_dma_chan_remove(struct fsldma_chan *chan) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1331 | { |
Ira Snyder | a1c0331 | 2010-01-06 13:34:05 +0000 | [diff] [blame] | 1332 | irq_dispose_mapping(chan->irq); |
| 1333 | list_del(&chan->common.device_node); |
| 1334 | iounmap(chan->regs); |
| 1335 | kfree(chan); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1338 | static int __devinit fsldma_of_probe(struct platform_device *op, |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1339 | const struct of_device_id *match) |
| 1340 | { |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 1341 | struct fsldma_device *fdev; |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1342 | struct device_node *child; |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1343 | int err; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1344 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 1345 | fdev = kzalloc(sizeof(*fdev), GFP_KERNEL); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1346 | if (!fdev) { |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1347 | dev_err(&op->dev, "No enough memory for 'priv'\n"); |
| 1348 | err = -ENOMEM; |
| 1349 | goto out_return; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1350 | } |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1351 | |
| 1352 | fdev->dev = &op->dev; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1353 | INIT_LIST_HEAD(&fdev->common.channels); |
| 1354 | |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1355 | /* ioremap the registers for use */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 1356 | fdev->regs = of_iomap(op->dev.of_node, 0); |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1357 | if (!fdev->regs) { |
| 1358 | dev_err(&op->dev, "unable to ioremap registers\n"); |
| 1359 | err = -ENOMEM; |
| 1360 | goto out_free_fdev; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1363 | /* map the channel IRQ if it exists, but don't hookup the handler yet */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 1364 | fdev->irq = irq_of_parse_and_map(op->dev.of_node, 0); |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1365 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1366 | dma_cap_set(DMA_MEMCPY, fdev->common.cap_mask); |
| 1367 | dma_cap_set(DMA_INTERRUPT, fdev->common.cap_mask); |
Ira Snyder | c1433041 | 2010-09-30 11:46:45 +0000 | [diff] [blame] | 1368 | dma_cap_set(DMA_SG, fdev->common.cap_mask); |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 1369 | dma_cap_set(DMA_SLAVE, fdev->common.cap_mask); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1370 | fdev->common.device_alloc_chan_resources = fsl_dma_alloc_chan_resources; |
| 1371 | fdev->common.device_free_chan_resources = fsl_dma_free_chan_resources; |
Zhang Wei | 2187c26 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 1372 | fdev->common.device_prep_dma_interrupt = fsl_dma_prep_interrupt; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1373 | fdev->common.device_prep_dma_memcpy = fsl_dma_prep_memcpy; |
Ira Snyder | c1433041 | 2010-09-30 11:46:45 +0000 | [diff] [blame] | 1374 | fdev->common.device_prep_dma_sg = fsl_dma_prep_sg; |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1375 | fdev->common.device_tx_status = fsl_tx_status; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1376 | fdev->common.device_issue_pending = fsl_dma_memcpy_issue_pending; |
Ira Snyder | bbea0b6 | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 1377 | fdev->common.device_prep_slave_sg = fsl_dma_prep_slave_sg; |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 1378 | fdev->common.device_control = fsl_dma_device_control; |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1379 | fdev->common.dev = &op->dev; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1380 | |
Li Yang | e2c8e425 | 2010-11-11 20:16:29 +0800 | [diff] [blame] | 1381 | dma_set_mask(&(op->dev), DMA_BIT_MASK(36)); |
| 1382 | |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1383 | dev_set_drvdata(&op->dev, fdev); |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1384 | |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1385 | /* |
| 1386 | * We cannot use of_platform_bus_probe() because there is no |
| 1387 | * of_platform_bus_remove(). Instead, we manually instantiate every DMA |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1388 | * channel object. |
| 1389 | */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 1390 | for_each_child_of_node(op->dev.of_node, child) { |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1391 | if (of_device_is_compatible(child, "fsl,eloplus-dma-channel")) { |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1392 | fsl_dma_chan_probe(fdev, child, |
| 1393 | FSL_DMA_IP_85XX | FSL_DMA_BIG_ENDIAN, |
| 1394 | "fsl,eloplus-dma-channel"); |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | if (of_device_is_compatible(child, "fsl,elo-dma-channel")) { |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1398 | fsl_dma_chan_probe(fdev, child, |
| 1399 | FSL_DMA_IP_83XX | FSL_DMA_LITTLE_ENDIAN, |
| 1400 | "fsl,elo-dma-channel"); |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1401 | } |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1402 | } |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1403 | |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1404 | /* |
| 1405 | * Hookup the IRQ handler(s) |
| 1406 | * |
| 1407 | * If we have a per-controller interrupt, we prefer that to the |
| 1408 | * per-channel interrupts to reduce the number of shared interrupt |
| 1409 | * handlers on the same IRQ line |
| 1410 | */ |
| 1411 | err = fsldma_request_irqs(fdev); |
| 1412 | if (err) { |
| 1413 | dev_err(fdev->dev, "unable to request IRQs\n"); |
| 1414 | goto out_free_fdev; |
| 1415 | } |
| 1416 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1417 | dma_async_device_register(&fdev->common); |
| 1418 | return 0; |
| 1419 | |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1420 | out_free_fdev: |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1421 | irq_dispose_mapping(fdev->irq); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1422 | kfree(fdev); |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1423 | out_return: |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1424 | return err; |
| 1425 | } |
| 1426 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1427 | static int fsldma_of_remove(struct platform_device *op) |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1428 | { |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 1429 | struct fsldma_device *fdev; |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1430 | unsigned int i; |
| 1431 | |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1432 | fdev = dev_get_drvdata(&op->dev); |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1433 | dma_async_device_unregister(&fdev->common); |
| 1434 | |
Ira Snyder | d3f620b | 2010-01-06 13:34:04 +0000 | [diff] [blame] | 1435 | fsldma_free_irqs(fdev); |
| 1436 | |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1437 | for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) { |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1438 | if (fdev->chan[i]) |
| 1439 | fsl_dma_chan_remove(fdev->chan[i]); |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1440 | } |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1441 | |
Ira Snyder | e7a2915 | 2010-01-06 13:34:03 +0000 | [diff] [blame] | 1442 | iounmap(fdev->regs); |
| 1443 | dev_set_drvdata(&op->dev, NULL); |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1444 | kfree(fdev); |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1445 | |
| 1446 | return 0; |
| 1447 | } |
| 1448 | |
Márton Németh | 4b1cf1f | 2010-02-02 23:41:06 -0700 | [diff] [blame] | 1449 | static const struct of_device_id fsldma_of_ids[] = { |
Kumar Gala | 049c9d4 | 2008-03-31 11:13:21 -0500 | [diff] [blame] | 1450 | { .compatible = "fsl,eloplus-dma", }, |
| 1451 | { .compatible = "fsl,elo-dma", }, |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1452 | {} |
| 1453 | }; |
| 1454 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 1455 | static struct of_platform_driver fsldma_of_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 1456 | .driver = { |
| 1457 | .name = "fsl-elo-dma", |
| 1458 | .owner = THIS_MODULE, |
| 1459 | .of_match_table = fsldma_of_ids, |
| 1460 | }, |
| 1461 | .probe = fsldma_of_probe, |
| 1462 | .remove = fsldma_of_remove, |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1463 | }; |
| 1464 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 1465 | /*----------------------------------------------------------------------------*/ |
| 1466 | /* Module Init / Exit */ |
| 1467 | /*----------------------------------------------------------------------------*/ |
| 1468 | |
| 1469 | static __init int fsldma_init(void) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1470 | { |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1471 | int ret; |
| 1472 | |
| 1473 | pr_info("Freescale Elo / Elo Plus DMA driver\n"); |
| 1474 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 1475 | ret = of_register_platform_driver(&fsldma_of_driver); |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1476 | if (ret) |
| 1477 | pr_err("fsldma: failed to register platform driver\n"); |
| 1478 | |
| 1479 | return ret; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 1482 | static void __exit fsldma_exit(void) |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1483 | { |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 1484 | of_unregister_platform_driver(&fsldma_of_driver); |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 1487 | subsys_initcall(fsldma_init); |
| 1488 | module_exit(fsldma_exit); |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 1489 | |
| 1490 | MODULE_DESCRIPTION("Freescale Elo / Elo Plus DMA driver"); |
| 1491 | MODULE_LICENSE("GPL"); |