Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006 ARM Ltd. |
| 3 | * Copyright (c) 2010 ST-Ericsson SA |
| 4 | * |
| 5 | * Author: Peter Pearse <peter.pearse@arm.com> |
| 6 | * Author: Linus Walleij <linus.walleij@stericsson.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the Free |
| 10 | * Software Foundation; either version 2 of the License, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 16 | * more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * this program; if not, write to the Free Software Foundation, Inc., 59 |
| 20 | * Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | * |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 22 | * The full GNU General Public License is in this distribution in the file |
| 23 | * called COPYING. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 24 | * |
| 25 | * Documentation: ARM DDI 0196G == PL080 |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 26 | * Documentation: ARM DDI 0218E == PL081 |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 27 | * |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 28 | * PL080 & PL081 both have 16 sets of DMA signals that can be routed to any |
| 29 | * channel. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 30 | * |
| 31 | * The PL080 has 8 channels available for simultaneous use, and the PL081 |
| 32 | * has only two channels. So on these DMA controllers the number of channels |
| 33 | * and the number of incoming DMA signals are two totally different things. |
| 34 | * It is usually not possible to theoretically handle all physical signals, |
| 35 | * so a multiplexing scheme with possible denial of use is necessary. |
| 36 | * |
| 37 | * The PL080 has a dual bus master, PL081 has a single master. |
| 38 | * |
| 39 | * Memory to peripheral transfer may be visualized as |
| 40 | * Get data from memory to DMAC |
| 41 | * Until no data left |
| 42 | * On burst request from peripheral |
| 43 | * Destination burst from DMAC to peripheral |
| 44 | * Clear burst request |
| 45 | * Raise terminal count interrupt |
| 46 | * |
| 47 | * For peripherals with a FIFO: |
| 48 | * Source burst size == half the depth of the peripheral FIFO |
| 49 | * Destination burst size == the depth of the peripheral FIFO |
| 50 | * |
| 51 | * (Bursts are irrelevant for mem to mem transfers - there are no burst |
| 52 | * signals, the DMA controller will simply facilitate its AHB master.) |
| 53 | * |
| 54 | * ASSUMES default (little) endianness for DMA transfers |
| 55 | * |
Russell King - ARM Linux | 9dc2c20 | 2011-01-03 22:33:06 +0000 | [diff] [blame] | 56 | * The PL08x has two flow control settings: |
| 57 | * - DMAC flow control: the transfer size defines the number of transfers |
| 58 | * which occur for the current LLI entry, and the DMAC raises TC at the |
| 59 | * end of every LLI entry. Observed behaviour shows the DMAC listening |
| 60 | * to both the BREQ and SREQ signals (contrary to documented), |
| 61 | * transferring data if either is active. The LBREQ and LSREQ signals |
| 62 | * are ignored. |
| 63 | * |
| 64 | * - Peripheral flow control: the transfer size is ignored (and should be |
| 65 | * zero). The data is transferred from the current LLI entry, until |
| 66 | * after the final transfer signalled by LBREQ or LSREQ. The DMAC |
| 67 | * will then move to the next LLI entry. |
| 68 | * |
| 69 | * Only the former works sanely with scatter lists, so we only implement |
| 70 | * the DMAC flow control method. However, peripherals which use the LBREQ |
| 71 | * and LSREQ signals (eg, MMCI) are unable to use this mode, which through |
| 72 | * these hardware restrictions prevents them from using scatter DMA. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 73 | * |
| 74 | * Global TODO: |
| 75 | * - Break out common code from arch/arm/mach-s3c64xx and share |
| 76 | */ |
| 77 | #include <linux/device.h> |
| 78 | #include <linux/init.h> |
| 79 | #include <linux/module.h> |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 80 | #include <linux/interrupt.h> |
| 81 | #include <linux/slab.h> |
Russell King - ARM Linux | 8179661 | 2011-01-27 12:37:44 +0000 | [diff] [blame] | 82 | #include <linux/delay.h> |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 83 | #include <linux/dmapool.h> |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 84 | #include <linux/dmaengine.h> |
Russell King - ARM Linux | 730404a | 2011-01-03 22:34:07 +0000 | [diff] [blame] | 85 | #include <linux/amba/bus.h> |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 86 | #include <linux/amba/pl08x.h> |
| 87 | #include <linux/debugfs.h> |
| 88 | #include <linux/seq_file.h> |
| 89 | |
| 90 | #include <asm/hardware/pl080.h> |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 91 | |
| 92 | #define DRIVER_NAME "pl08xdmac" |
| 93 | |
| 94 | /** |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 95 | * struct vendor_data - vendor-specific config parameters for PL08x derivatives |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 96 | * @channels: the number of channels available in this variant |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 97 | * @dualmaster: whether this version supports dual AHB masters or not. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 98 | */ |
| 99 | struct vendor_data { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 100 | u8 channels; |
| 101 | bool dualmaster; |
| 102 | }; |
| 103 | |
| 104 | /* |
| 105 | * PL08X private data structures |
Russell King - ARM Linux | e8b5e11 | 2011-01-03 22:30:24 +0000 | [diff] [blame] | 106 | * An LLI struct - see PL08x TRM. Note that next uses bit[0] as a bus bit, |
Russell King - ARM Linux | e25761d | 2011-01-03 22:37:52 +0000 | [diff] [blame] | 107 | * start & end do not - their bus bit info is in cctl. Also note that these |
| 108 | * are fixed 32-bit quantities. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 109 | */ |
Russell King - ARM Linux | 7cb72ad | 2011-01-03 22:35:28 +0000 | [diff] [blame] | 110 | struct pl08x_lli { |
Russell King - ARM Linux | e25761d | 2011-01-03 22:37:52 +0000 | [diff] [blame] | 111 | u32 src; |
| 112 | u32 dst; |
Russell King - ARM Linux | bfddfb4 | 2011-01-03 22:38:12 +0000 | [diff] [blame] | 113 | u32 lli; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 114 | u32 cctl; |
| 115 | }; |
| 116 | |
| 117 | /** |
| 118 | * struct pl08x_driver_data - the local state holder for the PL08x |
| 119 | * @slave: slave engine for this instance |
| 120 | * @memcpy: memcpy engine for this instance |
| 121 | * @base: virtual memory base (remapped) for the PL08x |
| 122 | * @adev: the corresponding AMBA (PrimeCell) bus entry |
| 123 | * @vd: vendor data for this PL08x variant |
| 124 | * @pd: platform data passed in from the platform/machine |
| 125 | * @phy_chans: array of data for the physical channels |
| 126 | * @pool: a pool for the LLI descriptors |
| 127 | * @pool_ctr: counter of LLIs in the pool |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 128 | * @lli_buses: bitmask to or in to LLI pointer selecting AHB port for LLI fetches |
| 129 | * @mem_buses: set to indicate memory transfers on AHB2. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 130 | * @lock: a spinlock for this struct |
| 131 | */ |
| 132 | struct pl08x_driver_data { |
| 133 | struct dma_device slave; |
| 134 | struct dma_device memcpy; |
| 135 | void __iomem *base; |
| 136 | struct amba_device *adev; |
Russell King - ARM Linux | f96ca9e | 2011-01-03 22:35:08 +0000 | [diff] [blame] | 137 | const struct vendor_data *vd; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 138 | struct pl08x_platform_data *pd; |
| 139 | struct pl08x_phy_chan *phy_chans; |
| 140 | struct dma_pool *pool; |
| 141 | int pool_ctr; |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 142 | u8 lli_buses; |
| 143 | u8 mem_buses; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 144 | spinlock_t lock; |
| 145 | }; |
| 146 | |
| 147 | /* |
| 148 | * PL08X specific defines |
| 149 | */ |
| 150 | |
| 151 | /* |
| 152 | * Memory boundaries: the manual for PL08x says that the controller |
| 153 | * cannot read past a 1KiB boundary, so these defines are used to |
| 154 | * create transfer LLIs that do not cross such boundaries. |
| 155 | */ |
| 156 | #define PL08X_BOUNDARY_SHIFT (10) /* 1KB 0x400 */ |
| 157 | #define PL08X_BOUNDARY_SIZE (1 << PL08X_BOUNDARY_SHIFT) |
| 158 | |
| 159 | /* Minimum period between work queue runs */ |
| 160 | #define PL08X_WQ_PERIODMIN 20 |
| 161 | |
| 162 | /* Size (bytes) of each LLI buffer allocated for one transfer */ |
| 163 | # define PL08X_LLI_TSFR_SIZE 0x2000 |
| 164 | |
Russell King - ARM Linux | e8b5e11 | 2011-01-03 22:30:24 +0000 | [diff] [blame] | 165 | /* Maximum times we call dma_pool_alloc on this pool without freeing */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 166 | #define PL08X_MAX_ALLOCS 0x40 |
Russell King - ARM Linux | 7cb72ad | 2011-01-03 22:35:28 +0000 | [diff] [blame] | 167 | #define MAX_NUM_TSFR_LLIS (PL08X_LLI_TSFR_SIZE/sizeof(struct pl08x_lli)) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 168 | #define PL08X_ALIGN 8 |
| 169 | |
| 170 | static inline struct pl08x_dma_chan *to_pl08x_chan(struct dma_chan *chan) |
| 171 | { |
| 172 | return container_of(chan, struct pl08x_dma_chan, chan); |
| 173 | } |
| 174 | |
Russell King - ARM Linux | 501e67e | 2011-01-03 22:44:57 +0000 | [diff] [blame] | 175 | static inline struct pl08x_txd *to_pl08x_txd(struct dma_async_tx_descriptor *tx) |
| 176 | { |
| 177 | return container_of(tx, struct pl08x_txd, tx); |
| 178 | } |
| 179 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 180 | /* |
| 181 | * Physical channel handling |
| 182 | */ |
| 183 | |
| 184 | /* Whether a certain channel is busy or not */ |
| 185 | static int pl08x_phy_channel_busy(struct pl08x_phy_chan *ch) |
| 186 | { |
| 187 | unsigned int val; |
| 188 | |
| 189 | val = readl(ch->base + PL080_CH_CONFIG); |
| 190 | return val & PL080_CONFIG_ACTIVE; |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * Set the initial DMA register values i.e. those for the first LLI |
Russell King - ARM Linux | e8b5e11 | 2011-01-03 22:30:24 +0000 | [diff] [blame] | 195 | * The next LLI pointer and the configuration interrupt bit have |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 196 | * been set when the LLIs were constructed. Poke them into the hardware |
| 197 | * and start the transfer. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 198 | */ |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 199 | static void pl08x_start_txd(struct pl08x_dma_chan *plchan, |
| 200 | struct pl08x_txd *txd) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 201 | { |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 202 | struct pl08x_driver_data *pl08x = plchan->host; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 203 | struct pl08x_phy_chan *phychan = plchan->phychan; |
Russell King - ARM Linux | 19524d7 | 2011-01-03 22:39:13 +0000 | [diff] [blame] | 204 | struct pl08x_lli *lli = &txd->llis_va[0]; |
Russell King - ARM Linux | 09b3c32 | 2011-01-03 22:39:53 +0000 | [diff] [blame] | 205 | u32 val; |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 206 | |
| 207 | plchan->at = txd; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 208 | |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 209 | /* Wait for channel inactive */ |
| 210 | while (pl08x_phy_channel_busy(phychan)) |
Russell King - ARM Linux | 19386b3 | 2011-01-03 22:36:29 +0000 | [diff] [blame] | 211 | cpu_relax(); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 212 | |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 213 | dev_vdbg(&pl08x->adev->dev, |
| 214 | "WRITE channel %d: csrc=0x%08x, cdst=0x%08x, " |
Russell King - ARM Linux | 19524d7 | 2011-01-03 22:39:13 +0000 | [diff] [blame] | 215 | "clli=0x%08x, cctl=0x%08x, ccfg=0x%08x\n", |
| 216 | phychan->id, lli->src, lli->dst, lli->lli, lli->cctl, |
Russell King - ARM Linux | 09b3c32 | 2011-01-03 22:39:53 +0000 | [diff] [blame] | 217 | txd->ccfg); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 218 | |
Russell King - ARM Linux | 19524d7 | 2011-01-03 22:39:13 +0000 | [diff] [blame] | 219 | writel(lli->src, phychan->base + PL080_CH_SRC_ADDR); |
| 220 | writel(lli->dst, phychan->base + PL080_CH_DST_ADDR); |
| 221 | writel(lli->lli, phychan->base + PL080_CH_LLI); |
| 222 | writel(lli->cctl, phychan->base + PL080_CH_CONTROL); |
Russell King - ARM Linux | 09b3c32 | 2011-01-03 22:39:53 +0000 | [diff] [blame] | 223 | writel(txd->ccfg, phychan->base + PL080_CH_CONFIG); |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 224 | |
| 225 | /* Enable the DMA channel */ |
| 226 | /* Do not access config register until channel shows as disabled */ |
| 227 | while (readl(pl08x->base + PL080_EN_CHAN) & (1 << phychan->id)) |
| 228 | cpu_relax(); |
| 229 | |
| 230 | /* Do not access config register until channel shows as inactive */ |
| 231 | val = readl(phychan->base + PL080_CH_CONFIG); |
| 232 | while ((val & PL080_CONFIG_ACTIVE) || (val & PL080_CONFIG_ENABLE)) |
| 233 | val = readl(phychan->base + PL080_CH_CONFIG); |
| 234 | |
| 235 | writel(val | PL080_CONFIG_ENABLE, phychan->base + PL080_CH_CONFIG); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /* |
Russell King - ARM Linux | 8179661 | 2011-01-27 12:37:44 +0000 | [diff] [blame] | 239 | * Pause the channel by setting the HALT bit. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 240 | * |
Russell King - ARM Linux | 8179661 | 2011-01-27 12:37:44 +0000 | [diff] [blame] | 241 | * For M->P transfers, pause the DMAC first and then stop the peripheral - |
| 242 | * the FIFO can only drain if the peripheral is still requesting data. |
| 243 | * (note: this can still timeout if the DMAC FIFO never drains of data.) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 244 | * |
Russell King - ARM Linux | 8179661 | 2011-01-27 12:37:44 +0000 | [diff] [blame] | 245 | * For P->M transfers, disable the peripheral first to stop it filling |
| 246 | * the DMAC FIFO, and then pause the DMAC. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 247 | */ |
| 248 | static void pl08x_pause_phy_chan(struct pl08x_phy_chan *ch) |
| 249 | { |
| 250 | u32 val; |
Russell King - ARM Linux | 8179661 | 2011-01-27 12:37:44 +0000 | [diff] [blame] | 251 | int timeout; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 252 | |
| 253 | /* Set the HALT bit and wait for the FIFO to drain */ |
| 254 | val = readl(ch->base + PL080_CH_CONFIG); |
| 255 | val |= PL080_CONFIG_HALT; |
| 256 | writel(val, ch->base + PL080_CH_CONFIG); |
| 257 | |
| 258 | /* Wait for channel inactive */ |
Russell King - ARM Linux | 8179661 | 2011-01-27 12:37:44 +0000 | [diff] [blame] | 259 | for (timeout = 1000; timeout; timeout--) { |
| 260 | if (!pl08x_phy_channel_busy(ch)) |
| 261 | break; |
| 262 | udelay(1); |
| 263 | } |
| 264 | if (pl08x_phy_channel_busy(ch)) |
| 265 | pr_err("pl08x: channel%u timeout waiting for pause\n", ch->id); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static void pl08x_resume_phy_chan(struct pl08x_phy_chan *ch) |
| 269 | { |
| 270 | u32 val; |
| 271 | |
| 272 | /* Clear the HALT bit */ |
| 273 | val = readl(ch->base + PL080_CH_CONFIG); |
| 274 | val &= ~PL080_CONFIG_HALT; |
| 275 | writel(val, ch->base + PL080_CH_CONFIG); |
| 276 | } |
| 277 | |
| 278 | |
Russell King - ARM Linux | fb52621 | 2011-01-27 12:32:53 +0000 | [diff] [blame] | 279 | /* |
| 280 | * pl08x_terminate_phy_chan() stops the channel, clears the FIFO and |
| 281 | * clears any pending interrupt status. This should not be used for |
| 282 | * an on-going transfer, but as a method of shutting down a channel |
| 283 | * (eg, when it's no longer used) or terminating a transfer. |
| 284 | */ |
| 285 | static void pl08x_terminate_phy_chan(struct pl08x_driver_data *pl08x, |
| 286 | struct pl08x_phy_chan *ch) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 287 | { |
Russell King - ARM Linux | fb52621 | 2011-01-27 12:32:53 +0000 | [diff] [blame] | 288 | u32 val = readl(ch->base + PL080_CH_CONFIG); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 289 | |
Russell King - ARM Linux | fb52621 | 2011-01-27 12:32:53 +0000 | [diff] [blame] | 290 | val &= ~(PL080_CONFIG_ENABLE | PL080_CONFIG_ERR_IRQ_MASK | |
| 291 | PL080_CONFIG_TC_IRQ_MASK); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 292 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 293 | writel(val, ch->base + PL080_CH_CONFIG); |
Russell King - ARM Linux | fb52621 | 2011-01-27 12:32:53 +0000 | [diff] [blame] | 294 | |
| 295 | writel(1 << ch->id, pl08x->base + PL080_ERR_CLEAR); |
| 296 | writel(1 << ch->id, pl08x->base + PL080_TC_CLEAR); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | static inline u32 get_bytes_in_cctl(u32 cctl) |
| 300 | { |
| 301 | /* The source width defines the number of bytes */ |
| 302 | u32 bytes = cctl & PL080_CONTROL_TRANSFER_SIZE_MASK; |
| 303 | |
| 304 | switch (cctl >> PL080_CONTROL_SWIDTH_SHIFT) { |
| 305 | case PL080_WIDTH_8BIT: |
| 306 | break; |
| 307 | case PL080_WIDTH_16BIT: |
| 308 | bytes *= 2; |
| 309 | break; |
| 310 | case PL080_WIDTH_32BIT: |
| 311 | bytes *= 4; |
| 312 | break; |
| 313 | } |
| 314 | return bytes; |
| 315 | } |
| 316 | |
| 317 | /* The channel should be paused when calling this */ |
| 318 | static u32 pl08x_getbytes_chan(struct pl08x_dma_chan *plchan) |
| 319 | { |
| 320 | struct pl08x_phy_chan *ch; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 321 | struct pl08x_txd *txd; |
| 322 | unsigned long flags; |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 323 | size_t bytes = 0; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 324 | |
| 325 | spin_lock_irqsave(&plchan->lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 326 | ch = plchan->phychan; |
| 327 | txd = plchan->at; |
| 328 | |
| 329 | /* |
Russell King - ARM Linux | db9f136 | 2011-01-03 22:38:32 +0000 | [diff] [blame] | 330 | * Follow the LLIs to get the number of remaining |
| 331 | * bytes in the currently active transaction. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 332 | */ |
| 333 | if (ch && txd) { |
Russell King - ARM Linux | 4c0df6a | 2011-01-03 22:36:50 +0000 | [diff] [blame] | 334 | u32 clli = readl(ch->base + PL080_CH_LLI) & ~PL080_LLI_LM_AHB2; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 335 | |
Russell King - ARM Linux | db9f136 | 2011-01-03 22:38:32 +0000 | [diff] [blame] | 336 | /* First get the remaining bytes in the active transfer */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 337 | bytes = get_bytes_in_cctl(readl(ch->base + PL080_CH_CONTROL)); |
| 338 | |
| 339 | if (clli) { |
Russell King - ARM Linux | db9f136 | 2011-01-03 22:38:32 +0000 | [diff] [blame] | 340 | struct pl08x_lli *llis_va = txd->llis_va; |
| 341 | dma_addr_t llis_bus = txd->llis_bus; |
| 342 | int index; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 343 | |
Russell King - ARM Linux | db9f136 | 2011-01-03 22:38:32 +0000 | [diff] [blame] | 344 | BUG_ON(clli < llis_bus || clli >= llis_bus + |
| 345 | sizeof(struct pl08x_lli) * MAX_NUM_TSFR_LLIS); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 346 | |
Russell King - ARM Linux | db9f136 | 2011-01-03 22:38:32 +0000 | [diff] [blame] | 347 | /* |
| 348 | * Locate the next LLI - as this is an array, |
| 349 | * it's simple maths to find. |
| 350 | */ |
| 351 | index = (clli - llis_bus) / sizeof(struct pl08x_lli); |
| 352 | |
| 353 | for (; index < MAX_NUM_TSFR_LLIS; index++) { |
| 354 | bytes += get_bytes_in_cctl(llis_va[index].cctl); |
| 355 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 356 | /* |
Russell King - ARM Linux | e8b5e11 | 2011-01-03 22:30:24 +0000 | [diff] [blame] | 357 | * A LLI pointer of 0 terminates the LLI list |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 358 | */ |
Russell King - ARM Linux | db9f136 | 2011-01-03 22:38:32 +0000 | [diff] [blame] | 359 | if (!llis_va[index].lli) |
| 360 | break; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | /* Sum up all queued transactions */ |
Russell King - ARM Linux | 15c1723 | 2011-01-03 22:44:36 +0000 | [diff] [blame] | 366 | if (!list_empty(&plchan->pend_list)) { |
Russell King - ARM Linux | db9f136 | 2011-01-03 22:38:32 +0000 | [diff] [blame] | 367 | struct pl08x_txd *txdi; |
Russell King - ARM Linux | 15c1723 | 2011-01-03 22:44:36 +0000 | [diff] [blame] | 368 | list_for_each_entry(txdi, &plchan->pend_list, node) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 369 | bytes += txdi->len; |
| 370 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | spin_unlock_irqrestore(&plchan->lock, flags); |
| 374 | |
| 375 | return bytes; |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * Allocate a physical channel for a virtual channel |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 380 | * |
| 381 | * Try to locate a physical channel to be used for this transfer. If all |
| 382 | * are taken return NULL and the requester will have to cope by using |
| 383 | * some fallback PIO mode or retrying later. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 384 | */ |
| 385 | static struct pl08x_phy_chan * |
| 386 | pl08x_get_phy_channel(struct pl08x_driver_data *pl08x, |
| 387 | struct pl08x_dma_chan *virt_chan) |
| 388 | { |
| 389 | struct pl08x_phy_chan *ch = NULL; |
| 390 | unsigned long flags; |
| 391 | int i; |
| 392 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 393 | for (i = 0; i < pl08x->vd->channels; i++) { |
| 394 | ch = &pl08x->phy_chans[i]; |
| 395 | |
| 396 | spin_lock_irqsave(&ch->lock, flags); |
| 397 | |
| 398 | if (!ch->serving) { |
| 399 | ch->serving = virt_chan; |
| 400 | ch->signal = -1; |
| 401 | spin_unlock_irqrestore(&ch->lock, flags); |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | spin_unlock_irqrestore(&ch->lock, flags); |
| 406 | } |
| 407 | |
| 408 | if (i == pl08x->vd->channels) { |
| 409 | /* No physical channel available, cope with it */ |
| 410 | return NULL; |
| 411 | } |
| 412 | |
| 413 | return ch; |
| 414 | } |
| 415 | |
| 416 | static inline void pl08x_put_phy_channel(struct pl08x_driver_data *pl08x, |
| 417 | struct pl08x_phy_chan *ch) |
| 418 | { |
| 419 | unsigned long flags; |
| 420 | |
Russell King - ARM Linux | fb52621 | 2011-01-27 12:32:53 +0000 | [diff] [blame] | 421 | spin_lock_irqsave(&ch->lock, flags); |
| 422 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 423 | /* Stop the channel and clear its interrupts */ |
Russell King - ARM Linux | fb52621 | 2011-01-27 12:32:53 +0000 | [diff] [blame] | 424 | pl08x_terminate_phy_chan(pl08x, ch); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 425 | |
| 426 | /* Mark it as free */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 427 | ch->serving = NULL; |
| 428 | spin_unlock_irqrestore(&ch->lock, flags); |
| 429 | } |
| 430 | |
| 431 | /* |
| 432 | * LLI handling |
| 433 | */ |
| 434 | |
| 435 | static inline unsigned int pl08x_get_bytes_for_cctl(unsigned int coded) |
| 436 | { |
| 437 | switch (coded) { |
| 438 | case PL080_WIDTH_8BIT: |
| 439 | return 1; |
| 440 | case PL080_WIDTH_16BIT: |
| 441 | return 2; |
| 442 | case PL080_WIDTH_32BIT: |
| 443 | return 4; |
| 444 | default: |
| 445 | break; |
| 446 | } |
| 447 | BUG(); |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static inline u32 pl08x_cctl_bits(u32 cctl, u8 srcwidth, u8 dstwidth, |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 452 | size_t tsize) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 453 | { |
| 454 | u32 retbits = cctl; |
| 455 | |
Russell King - ARM Linux | e8b5e11 | 2011-01-03 22:30:24 +0000 | [diff] [blame] | 456 | /* Remove all src, dst and transfer size bits */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 457 | retbits &= ~PL080_CONTROL_DWIDTH_MASK; |
| 458 | retbits &= ~PL080_CONTROL_SWIDTH_MASK; |
| 459 | retbits &= ~PL080_CONTROL_TRANSFER_SIZE_MASK; |
| 460 | |
| 461 | /* Then set the bits according to the parameters */ |
| 462 | switch (srcwidth) { |
| 463 | case 1: |
| 464 | retbits |= PL080_WIDTH_8BIT << PL080_CONTROL_SWIDTH_SHIFT; |
| 465 | break; |
| 466 | case 2: |
| 467 | retbits |= PL080_WIDTH_16BIT << PL080_CONTROL_SWIDTH_SHIFT; |
| 468 | break; |
| 469 | case 4: |
| 470 | retbits |= PL080_WIDTH_32BIT << PL080_CONTROL_SWIDTH_SHIFT; |
| 471 | break; |
| 472 | default: |
| 473 | BUG(); |
| 474 | break; |
| 475 | } |
| 476 | |
| 477 | switch (dstwidth) { |
| 478 | case 1: |
| 479 | retbits |= PL080_WIDTH_8BIT << PL080_CONTROL_DWIDTH_SHIFT; |
| 480 | break; |
| 481 | case 2: |
| 482 | retbits |= PL080_WIDTH_16BIT << PL080_CONTROL_DWIDTH_SHIFT; |
| 483 | break; |
| 484 | case 4: |
| 485 | retbits |= PL080_WIDTH_32BIT << PL080_CONTROL_DWIDTH_SHIFT; |
| 486 | break; |
| 487 | default: |
| 488 | BUG(); |
| 489 | break; |
| 490 | } |
| 491 | |
| 492 | retbits |= tsize << PL080_CONTROL_TRANSFER_SIZE_SHIFT; |
| 493 | return retbits; |
| 494 | } |
| 495 | |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 496 | struct pl08x_lli_build_data { |
| 497 | struct pl08x_txd *txd; |
| 498 | struct pl08x_driver_data *pl08x; |
| 499 | struct pl08x_bus_data srcbus; |
| 500 | struct pl08x_bus_data dstbus; |
| 501 | size_t remainder; |
| 502 | }; |
| 503 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 504 | /* |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 505 | * Autoselect a master bus to use for the transfer this prefers the |
| 506 | * destination bus if both available if fixed address on one bus the |
| 507 | * other will be chosen |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 508 | */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 509 | static void pl08x_choose_master_bus(struct pl08x_lli_build_data *bd, |
| 510 | struct pl08x_bus_data **mbus, struct pl08x_bus_data **sbus, u32 cctl) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 511 | { |
| 512 | if (!(cctl & PL080_CONTROL_DST_INCR)) { |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 513 | *mbus = &bd->srcbus; |
| 514 | *sbus = &bd->dstbus; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 515 | } else if (!(cctl & PL080_CONTROL_SRC_INCR)) { |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 516 | *mbus = &bd->dstbus; |
| 517 | *sbus = &bd->srcbus; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 518 | } else { |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 519 | if (bd->dstbus.buswidth == 4) { |
| 520 | *mbus = &bd->dstbus; |
| 521 | *sbus = &bd->srcbus; |
| 522 | } else if (bd->srcbus.buswidth == 4) { |
| 523 | *mbus = &bd->srcbus; |
| 524 | *sbus = &bd->dstbus; |
| 525 | } else if (bd->dstbus.buswidth == 2) { |
| 526 | *mbus = &bd->dstbus; |
| 527 | *sbus = &bd->srcbus; |
| 528 | } else if (bd->srcbus.buswidth == 2) { |
| 529 | *mbus = &bd->srcbus; |
| 530 | *sbus = &bd->dstbus; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 531 | } else { |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 532 | /* bd->srcbus.buswidth == 1 */ |
| 533 | *mbus = &bd->dstbus; |
| 534 | *sbus = &bd->srcbus; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | /* |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 540 | * Fills in one LLI for a certain transfer descriptor and advance the counter |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 541 | */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 542 | static void pl08x_fill_lli_for_desc(struct pl08x_lli_build_data *bd, |
| 543 | int num_llis, int len, u32 cctl) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 544 | { |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 545 | struct pl08x_lli *llis_va = bd->txd->llis_va; |
| 546 | dma_addr_t llis_bus = bd->txd->llis_bus; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 547 | |
| 548 | BUG_ON(num_llis >= MAX_NUM_TSFR_LLIS); |
| 549 | |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 550 | llis_va[num_llis].cctl = cctl; |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 551 | llis_va[num_llis].src = bd->srcbus.addr; |
| 552 | llis_va[num_llis].dst = bd->dstbus.addr; |
Russell King - ARM Linux | bfddfb4 | 2011-01-03 22:38:12 +0000 | [diff] [blame] | 553 | llis_va[num_llis].lli = llis_bus + (num_llis + 1) * sizeof(struct pl08x_lli); |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 554 | if (bd->pl08x->lli_buses & PL08X_AHB2) |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 555 | llis_va[num_llis].lli |= PL080_LLI_LM_AHB2; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 556 | |
| 557 | if (cctl & PL080_CONTROL_SRC_INCR) |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 558 | bd->srcbus.addr += len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 559 | if (cctl & PL080_CONTROL_DST_INCR) |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 560 | bd->dstbus.addr += len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 561 | |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 562 | BUG_ON(bd->remainder < len); |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 563 | |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 564 | bd->remainder -= len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /* |
Russell King - ARM Linux | b61be8d | 2011-01-03 22:42:14 +0000 | [diff] [blame] | 568 | * Return number of bytes to fill to boundary, or len. |
| 569 | * This calculation works for any value of addr. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 570 | */ |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 571 | static inline size_t pl08x_pre_boundary(u32 addr, size_t len) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 572 | { |
Russell King - ARM Linux | b61be8d | 2011-01-03 22:42:14 +0000 | [diff] [blame] | 573 | size_t boundary_len = PL08X_BOUNDARY_SIZE - |
| 574 | (addr & (PL08X_BOUNDARY_SIZE - 1)); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 575 | |
Russell King - ARM Linux | b61be8d | 2011-01-03 22:42:14 +0000 | [diff] [blame] | 576 | return min(boundary_len, len); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /* |
| 580 | * This fills in the table of LLIs for the transfer descriptor |
| 581 | * Note that we assume we never have to change the burst sizes |
| 582 | * Return 0 for error |
| 583 | */ |
| 584 | static int pl08x_fill_llis_for_desc(struct pl08x_driver_data *pl08x, |
| 585 | struct pl08x_txd *txd) |
| 586 | { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 587 | struct pl08x_bus_data *mbus, *sbus; |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 588 | struct pl08x_lli_build_data bd; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 589 | int num_llis = 0; |
| 590 | u32 cctl; |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 591 | size_t max_bytes_per_lli; |
| 592 | size_t total_bytes = 0; |
Russell King - ARM Linux | 7cb72ad | 2011-01-03 22:35:28 +0000 | [diff] [blame] | 593 | struct pl08x_lli *llis_va; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 594 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 595 | txd->llis_va = dma_pool_alloc(pl08x->pool, GFP_NOWAIT, |
| 596 | &txd->llis_bus); |
| 597 | if (!txd->llis_va) { |
| 598 | dev_err(&pl08x->adev->dev, "%s no memory for llis\n", __func__); |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | pl08x->pool_ctr++; |
| 603 | |
Russell King - ARM Linux | 70b5ed6 | 2011-01-03 22:40:13 +0000 | [diff] [blame] | 604 | /* Get the default CCTL */ |
| 605 | cctl = txd->cctl; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 606 | |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 607 | bd.txd = txd; |
| 608 | bd.pl08x = pl08x; |
Russell King - ARM Linux | d7244e9 | 2011-01-03 22:43:35 +0000 | [diff] [blame] | 609 | bd.srcbus.addr = txd->src_addr; |
| 610 | bd.dstbus.addr = txd->dst_addr; |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 611 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 612 | /* Find maximum width of the source bus */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 613 | bd.srcbus.maxwidth = |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 614 | pl08x_get_bytes_for_cctl((cctl & PL080_CONTROL_SWIDTH_MASK) >> |
| 615 | PL080_CONTROL_SWIDTH_SHIFT); |
| 616 | |
| 617 | /* Find maximum width of the destination bus */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 618 | bd.dstbus.maxwidth = |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 619 | pl08x_get_bytes_for_cctl((cctl & PL080_CONTROL_DWIDTH_MASK) >> |
| 620 | PL080_CONTROL_DWIDTH_SHIFT); |
| 621 | |
| 622 | /* Set up the bus widths to the maximum */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 623 | bd.srcbus.buswidth = bd.srcbus.maxwidth; |
| 624 | bd.dstbus.buswidth = bd.dstbus.maxwidth; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 625 | dev_vdbg(&pl08x->adev->dev, |
| 626 | "%s source bus is %d bytes wide, dest bus is %d bytes wide\n", |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 627 | __func__, bd.srcbus.buswidth, bd.dstbus.buswidth); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 628 | |
| 629 | |
| 630 | /* |
| 631 | * Bytes transferred == tsize * MIN(buswidths), not max(buswidths) |
| 632 | */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 633 | max_bytes_per_lli = min(bd.srcbus.buswidth, bd.dstbus.buswidth) * |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 634 | PL080_CONTROL_TRANSFER_SIZE_MASK; |
| 635 | dev_vdbg(&pl08x->adev->dev, |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 636 | "%s max bytes per lli = %zu\n", |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 637 | __func__, max_bytes_per_lli); |
| 638 | |
| 639 | /* We need to count this down to zero */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 640 | bd.remainder = txd->len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 641 | dev_vdbg(&pl08x->adev->dev, |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 642 | "%s remainder = %zu\n", |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 643 | __func__, bd.remainder); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 644 | |
| 645 | /* |
| 646 | * Choose bus to align to |
| 647 | * - prefers destination bus if both available |
| 648 | * - if fixed address on one bus chooses other |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 649 | */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 650 | pl08x_choose_master_bus(&bd, &mbus, &sbus, cctl); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 651 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 652 | if (txd->len < mbus->buswidth) { |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 653 | /* Less than a bus width available - send as single bytes */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 654 | while (bd.remainder) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 655 | dev_vdbg(&pl08x->adev->dev, |
| 656 | "%s single byte LLIs for a transfer of " |
Russell King - ARM Linux | 9c13299 | 2011-01-03 22:33:47 +0000 | [diff] [blame] | 657 | "less than a bus width (remain 0x%08x)\n", |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 658 | __func__, bd.remainder); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 659 | cctl = pl08x_cctl_bits(cctl, 1, 1, 1); |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 660 | pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 661 | total_bytes++; |
| 662 | } |
| 663 | } else { |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 664 | /* Make one byte LLIs until master bus is aligned */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 665 | while ((mbus->addr) % (mbus->buswidth)) { |
| 666 | dev_vdbg(&pl08x->adev->dev, |
| 667 | "%s adjustment lli for less than bus width " |
Russell King - ARM Linux | 9c13299 | 2011-01-03 22:33:47 +0000 | [diff] [blame] | 668 | "(remain 0x%08x)\n", |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 669 | __func__, bd.remainder); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 670 | cctl = pl08x_cctl_bits(cctl, 1, 1, 1); |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 671 | pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 672 | total_bytes++; |
| 673 | } |
| 674 | |
| 675 | /* |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 676 | * Master now aligned |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 677 | * - if slave is not then we must set its width down |
| 678 | */ |
| 679 | if (sbus->addr % sbus->buswidth) { |
| 680 | dev_dbg(&pl08x->adev->dev, |
| 681 | "%s set down bus width to one byte\n", |
| 682 | __func__); |
| 683 | |
| 684 | sbus->buswidth = 1; |
| 685 | } |
| 686 | |
| 687 | /* |
| 688 | * Make largest possible LLIs until less than one bus |
| 689 | * width left |
| 690 | */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 691 | while (bd.remainder > (mbus->buswidth - 1)) { |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 692 | size_t lli_len, target_len, tsize, odd_bytes; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 693 | |
| 694 | /* |
| 695 | * If enough left try to send max possible, |
| 696 | * otherwise try to send the remainder |
| 697 | */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 698 | target_len = min(bd.remainder, max_bytes_per_lli); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 699 | |
| 700 | /* |
Russell King - ARM Linux | 5f638b4 | 2011-01-03 22:42:55 +0000 | [diff] [blame] | 701 | * Set bus lengths for incrementing buses to the |
| 702 | * number of bytes which fill to next memory boundary, |
| 703 | * limiting on the target length calculated above. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 704 | */ |
| 705 | if (cctl & PL080_CONTROL_SRC_INCR) |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 706 | bd.srcbus.fill_bytes = |
| 707 | pl08x_pre_boundary(bd.srcbus.addr, |
Russell King - ARM Linux | 5f638b4 | 2011-01-03 22:42:55 +0000 | [diff] [blame] | 708 | target_len); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 709 | else |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 710 | bd.srcbus.fill_bytes = target_len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 711 | |
| 712 | if (cctl & PL080_CONTROL_DST_INCR) |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 713 | bd.dstbus.fill_bytes = |
| 714 | pl08x_pre_boundary(bd.dstbus.addr, |
Russell King - ARM Linux | 5f638b4 | 2011-01-03 22:42:55 +0000 | [diff] [blame] | 715 | target_len); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 716 | else |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 717 | bd.dstbus.fill_bytes = target_len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 718 | |
Russell King - ARM Linux | 5f638b4 | 2011-01-03 22:42:55 +0000 | [diff] [blame] | 719 | /* Find the nearest */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 720 | lli_len = min(bd.srcbus.fill_bytes, |
| 721 | bd.dstbus.fill_bytes); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 722 | |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 723 | BUG_ON(lli_len > bd.remainder); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 724 | |
| 725 | if (lli_len <= 0) { |
| 726 | dev_err(&pl08x->adev->dev, |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 727 | "%s lli_len is %zu, <= 0\n", |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 728 | __func__, lli_len); |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | if (lli_len == target_len) { |
| 733 | /* |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 734 | * Can send what we wanted. |
| 735 | * Maintain alignment |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 736 | */ |
| 737 | lli_len = (lli_len/mbus->buswidth) * |
| 738 | mbus->buswidth; |
| 739 | odd_bytes = 0; |
| 740 | } else { |
| 741 | /* |
| 742 | * So now we know how many bytes to transfer |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 743 | * to get to the nearest boundary. The next |
| 744 | * LLI will past the boundary. However, we |
| 745 | * may be working to a boundary on the slave |
| 746 | * bus. We need to ensure the master stays |
| 747 | * aligned, and that we are working in |
| 748 | * multiples of the bus widths. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 749 | */ |
| 750 | odd_bytes = lli_len % mbus->buswidth; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 751 | lli_len -= odd_bytes; |
| 752 | |
| 753 | } |
| 754 | |
| 755 | if (lli_len) { |
| 756 | /* |
| 757 | * Check against minimum bus alignment: |
| 758 | * Calculate actual transfer size in relation |
| 759 | * to bus width an get a maximum remainder of |
| 760 | * the smallest bus width - 1 |
| 761 | */ |
| 762 | /* FIXME: use round_down()? */ |
| 763 | tsize = lli_len / min(mbus->buswidth, |
| 764 | sbus->buswidth); |
| 765 | lli_len = tsize * min(mbus->buswidth, |
| 766 | sbus->buswidth); |
| 767 | |
| 768 | if (target_len != lli_len) { |
| 769 | dev_vdbg(&pl08x->adev->dev, |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 770 | "%s can't send what we want. Desired 0x%08zx, lli of 0x%08zx bytes in txd of 0x%08zx\n", |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 771 | __func__, target_len, lli_len, txd->len); |
| 772 | } |
| 773 | |
| 774 | cctl = pl08x_cctl_bits(cctl, |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 775 | bd.srcbus.buswidth, |
| 776 | bd.dstbus.buswidth, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 777 | tsize); |
| 778 | |
| 779 | dev_vdbg(&pl08x->adev->dev, |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 780 | "%s fill lli with single lli chunk of size 0x%08zx (remainder 0x%08zx)\n", |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 781 | __func__, lli_len, bd.remainder); |
| 782 | pl08x_fill_lli_for_desc(&bd, num_llis++, |
| 783 | lli_len, cctl); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 784 | total_bytes += lli_len; |
| 785 | } |
| 786 | |
| 787 | |
| 788 | if (odd_bytes) { |
| 789 | /* |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 790 | * Creep past the boundary, maintaining |
| 791 | * master alignment |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 792 | */ |
| 793 | int j; |
| 794 | for (j = 0; (j < mbus->buswidth) |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 795 | && (bd.remainder); j++) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 796 | cctl = pl08x_cctl_bits(cctl, 1, 1, 1); |
| 797 | dev_vdbg(&pl08x->adev->dev, |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 798 | "%s align with boundary, single byte (remain 0x%08zx)\n", |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 799 | __func__, bd.remainder); |
| 800 | pl08x_fill_lli_for_desc(&bd, |
| 801 | num_llis++, 1, cctl); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 802 | total_bytes++; |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * Send any odd bytes |
| 809 | */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 810 | while (bd.remainder) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 811 | cctl = pl08x_cctl_bits(cctl, 1, 1, 1); |
| 812 | dev_vdbg(&pl08x->adev->dev, |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 813 | "%s align with boundary, single odd byte (remain %zu)\n", |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 814 | __func__, bd.remainder); |
| 815 | pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 816 | total_bytes++; |
| 817 | } |
| 818 | } |
| 819 | if (total_bytes != txd->len) { |
| 820 | dev_err(&pl08x->adev->dev, |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 821 | "%s size of encoded lli:s don't match total txd, transferred 0x%08zx from size 0x%08zx\n", |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 822 | __func__, total_bytes, txd->len); |
| 823 | return 0; |
| 824 | } |
| 825 | |
| 826 | if (num_llis >= MAX_NUM_TSFR_LLIS) { |
| 827 | dev_err(&pl08x->adev->dev, |
| 828 | "%s need to increase MAX_NUM_TSFR_LLIS from 0x%08x\n", |
| 829 | __func__, (u32) MAX_NUM_TSFR_LLIS); |
| 830 | return 0; |
| 831 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 832 | |
Russell King - ARM Linux | b58b6b5 | 2011-01-03 22:34:48 +0000 | [diff] [blame] | 833 | llis_va = txd->llis_va; |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 834 | /* The final LLI terminates the LLI. */ |
Russell King - ARM Linux | bfddfb4 | 2011-01-03 22:38:12 +0000 | [diff] [blame] | 835 | llis_va[num_llis - 1].lli = 0; |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 836 | /* The final LLI element shall also fire an interrupt. */ |
Russell King - ARM Linux | b58b6b5 | 2011-01-03 22:34:48 +0000 | [diff] [blame] | 837 | llis_va[num_llis - 1].cctl |= PL080_CONTROL_TC_IRQ_EN; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 838 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 839 | #ifdef VERBOSE_DEBUG |
| 840 | { |
| 841 | int i; |
| 842 | |
| 843 | for (i = 0; i < num_llis; i++) { |
| 844 | dev_vdbg(&pl08x->adev->dev, |
Russell King - ARM Linux | 9c13299 | 2011-01-03 22:33:47 +0000 | [diff] [blame] | 845 | "lli %d @%p: csrc=0x%08x, cdst=0x%08x, cctl=0x%08x, clli=0x%08x\n", |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 846 | i, |
| 847 | &llis_va[i], |
| 848 | llis_va[i].src, |
| 849 | llis_va[i].dst, |
| 850 | llis_va[i].cctl, |
Russell King - ARM Linux | bfddfb4 | 2011-01-03 22:38:12 +0000 | [diff] [blame] | 851 | llis_va[i].lli |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 852 | ); |
| 853 | } |
| 854 | } |
| 855 | #endif |
| 856 | |
| 857 | return num_llis; |
| 858 | } |
| 859 | |
| 860 | /* You should call this with the struct pl08x lock held */ |
| 861 | static void pl08x_free_txd(struct pl08x_driver_data *pl08x, |
| 862 | struct pl08x_txd *txd) |
| 863 | { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 864 | /* Free the LLI */ |
Russell King - ARM Linux | 56b6188 | 2011-01-03 22:37:10 +0000 | [diff] [blame] | 865 | dma_pool_free(pl08x->pool, txd->llis_va, txd->llis_bus); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 866 | |
| 867 | pl08x->pool_ctr--; |
| 868 | |
| 869 | kfree(txd); |
| 870 | } |
| 871 | |
| 872 | static void pl08x_free_txd_list(struct pl08x_driver_data *pl08x, |
| 873 | struct pl08x_dma_chan *plchan) |
| 874 | { |
| 875 | struct pl08x_txd *txdi = NULL; |
| 876 | struct pl08x_txd *next; |
| 877 | |
Russell King - ARM Linux | 15c1723 | 2011-01-03 22:44:36 +0000 | [diff] [blame] | 878 | if (!list_empty(&plchan->pend_list)) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 879 | list_for_each_entry_safe(txdi, |
Russell King - ARM Linux | 15c1723 | 2011-01-03 22:44:36 +0000 | [diff] [blame] | 880 | next, &plchan->pend_list, node) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 881 | list_del(&txdi->node); |
| 882 | pl08x_free_txd(pl08x, txdi); |
| 883 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
| 887 | /* |
| 888 | * The DMA ENGINE API |
| 889 | */ |
| 890 | static int pl08x_alloc_chan_resources(struct dma_chan *chan) |
| 891 | { |
| 892 | return 0; |
| 893 | } |
| 894 | |
| 895 | static void pl08x_free_chan_resources(struct dma_chan *chan) |
| 896 | { |
| 897 | } |
| 898 | |
| 899 | /* |
| 900 | * This should be called with the channel plchan->lock held |
| 901 | */ |
| 902 | static int prep_phy_channel(struct pl08x_dma_chan *plchan, |
| 903 | struct pl08x_txd *txd) |
| 904 | { |
| 905 | struct pl08x_driver_data *pl08x = plchan->host; |
| 906 | struct pl08x_phy_chan *ch; |
| 907 | int ret; |
| 908 | |
| 909 | /* Check if we already have a channel */ |
| 910 | if (plchan->phychan) |
| 911 | return 0; |
| 912 | |
| 913 | ch = pl08x_get_phy_channel(pl08x, plchan); |
| 914 | if (!ch) { |
| 915 | /* No physical channel available, cope with it */ |
| 916 | dev_dbg(&pl08x->adev->dev, "no physical channel available for xfer on %s\n", plchan->name); |
| 917 | return -EBUSY; |
| 918 | } |
| 919 | |
| 920 | /* |
| 921 | * OK we have a physical channel: for memcpy() this is all we |
| 922 | * need, but for slaves the physical signals may be muxed! |
| 923 | * Can the platform allow us to use this channel? |
| 924 | */ |
| 925 | if (plchan->slave && |
| 926 | ch->signal < 0 && |
| 927 | pl08x->pd->get_signal) { |
| 928 | ret = pl08x->pd->get_signal(plchan); |
| 929 | if (ret < 0) { |
| 930 | dev_dbg(&pl08x->adev->dev, |
| 931 | "unable to use physical channel %d for transfer on %s due to platform restrictions\n", |
| 932 | ch->id, plchan->name); |
| 933 | /* Release physical channel & return */ |
| 934 | pl08x_put_phy_channel(pl08x, ch); |
| 935 | return -EBUSY; |
| 936 | } |
| 937 | ch->signal = ret; |
Russell King - ARM Linux | 09b3c32 | 2011-01-03 22:39:53 +0000 | [diff] [blame] | 938 | |
| 939 | /* Assign the flow control signal to this channel */ |
| 940 | if (txd->direction == DMA_TO_DEVICE) |
| 941 | txd->ccfg |= ch->signal << PL080_CONFIG_DST_SEL_SHIFT; |
| 942 | else if (txd->direction == DMA_FROM_DEVICE) |
| 943 | txd->ccfg |= ch->signal << PL080_CONFIG_SRC_SEL_SHIFT; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | dev_dbg(&pl08x->adev->dev, "allocated physical channel %d and signal %d for xfer on %s\n", |
| 947 | ch->id, |
| 948 | ch->signal, |
| 949 | plchan->name); |
| 950 | |
Russell King - ARM Linux | 8087aac | 2011-01-03 22:45:17 +0000 | [diff] [blame] | 951 | plchan->phychan_hold++; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 952 | plchan->phychan = ch; |
| 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
Russell King - ARM Linux | 8c8cc2b | 2011-01-03 22:36:09 +0000 | [diff] [blame] | 957 | static void release_phy_channel(struct pl08x_dma_chan *plchan) |
| 958 | { |
| 959 | struct pl08x_driver_data *pl08x = plchan->host; |
| 960 | |
| 961 | if ((plchan->phychan->signal >= 0) && pl08x->pd->put_signal) { |
| 962 | pl08x->pd->put_signal(plchan); |
| 963 | plchan->phychan->signal = -1; |
| 964 | } |
| 965 | pl08x_put_phy_channel(pl08x, plchan->phychan); |
| 966 | plchan->phychan = NULL; |
| 967 | } |
| 968 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 969 | static dma_cookie_t pl08x_tx_submit(struct dma_async_tx_descriptor *tx) |
| 970 | { |
| 971 | struct pl08x_dma_chan *plchan = to_pl08x_chan(tx->chan); |
Russell King - ARM Linux | 501e67e | 2011-01-03 22:44:57 +0000 | [diff] [blame] | 972 | struct pl08x_txd *txd = to_pl08x_txd(tx); |
Russell King - ARM Linux | c370e59 | 2011-01-03 22:45:37 +0000 | [diff] [blame] | 973 | unsigned long flags; |
| 974 | |
| 975 | spin_lock_irqsave(&plchan->lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 976 | |
Russell King - ARM Linux | 91aa5fa | 2011-01-03 22:31:04 +0000 | [diff] [blame] | 977 | plchan->chan.cookie += 1; |
| 978 | if (plchan->chan.cookie < 0) |
| 979 | plchan->chan.cookie = 1; |
| 980 | tx->cookie = plchan->chan.cookie; |
Russell King - ARM Linux | 501e67e | 2011-01-03 22:44:57 +0000 | [diff] [blame] | 981 | |
| 982 | /* Put this onto the pending list */ |
| 983 | list_add_tail(&txd->node, &plchan->pend_list); |
| 984 | |
| 985 | /* |
| 986 | * If there was no physical channel available for this memcpy, |
| 987 | * stack the request up and indicate that the channel is waiting |
| 988 | * for a free physical channel. |
| 989 | */ |
| 990 | if (!plchan->slave && !plchan->phychan) { |
| 991 | /* Do this memcpy whenever there is a channel ready */ |
| 992 | plchan->state = PL08X_CHAN_WAITING; |
| 993 | plchan->waiting = txd; |
Russell King - ARM Linux | 8087aac | 2011-01-03 22:45:17 +0000 | [diff] [blame] | 994 | } else { |
| 995 | plchan->phychan_hold--; |
Russell King - ARM Linux | 501e67e | 2011-01-03 22:44:57 +0000 | [diff] [blame] | 996 | } |
| 997 | |
Russell King - ARM Linux | c370e59 | 2011-01-03 22:45:37 +0000 | [diff] [blame] | 998 | spin_unlock_irqrestore(&plchan->lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 999 | |
| 1000 | return tx->cookie; |
| 1001 | } |
| 1002 | |
| 1003 | static struct dma_async_tx_descriptor *pl08x_prep_dma_interrupt( |
| 1004 | struct dma_chan *chan, unsigned long flags) |
| 1005 | { |
| 1006 | struct dma_async_tx_descriptor *retval = NULL; |
| 1007 | |
| 1008 | return retval; |
| 1009 | } |
| 1010 | |
| 1011 | /* |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1012 | * Code accessing dma_async_is_complete() in a tight loop may give problems. |
| 1013 | * If slaves are relying on interrupts to signal completion this function |
| 1014 | * must not be called with interrupts disabled. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1015 | */ |
| 1016 | static enum dma_status |
| 1017 | pl08x_dma_tx_status(struct dma_chan *chan, |
| 1018 | dma_cookie_t cookie, |
| 1019 | struct dma_tx_state *txstate) |
| 1020 | { |
| 1021 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1022 | dma_cookie_t last_used; |
| 1023 | dma_cookie_t last_complete; |
| 1024 | enum dma_status ret; |
| 1025 | u32 bytesleft = 0; |
| 1026 | |
Russell King - ARM Linux | 91aa5fa | 2011-01-03 22:31:04 +0000 | [diff] [blame] | 1027 | last_used = plchan->chan.cookie; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1028 | last_complete = plchan->lc; |
| 1029 | |
| 1030 | ret = dma_async_is_complete(cookie, last_complete, last_used); |
| 1031 | if (ret == DMA_SUCCESS) { |
| 1032 | dma_set_tx_state(txstate, last_complete, last_used, 0); |
| 1033 | return ret; |
| 1034 | } |
| 1035 | |
| 1036 | /* |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1037 | * This cookie not complete yet |
| 1038 | */ |
Russell King - ARM Linux | 91aa5fa | 2011-01-03 22:31:04 +0000 | [diff] [blame] | 1039 | last_used = plchan->chan.cookie; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1040 | last_complete = plchan->lc; |
| 1041 | |
| 1042 | /* Get number of bytes left in the active transactions and queue */ |
| 1043 | bytesleft = pl08x_getbytes_chan(plchan); |
| 1044 | |
| 1045 | dma_set_tx_state(txstate, last_complete, last_used, |
| 1046 | bytesleft); |
| 1047 | |
| 1048 | if (plchan->state == PL08X_CHAN_PAUSED) |
| 1049 | return DMA_PAUSED; |
| 1050 | |
| 1051 | /* Whether waiting or running, we're in progress */ |
| 1052 | return DMA_IN_PROGRESS; |
| 1053 | } |
| 1054 | |
| 1055 | /* PrimeCell DMA extension */ |
| 1056 | struct burst_table { |
| 1057 | int burstwords; |
| 1058 | u32 reg; |
| 1059 | }; |
| 1060 | |
| 1061 | static const struct burst_table burst_sizes[] = { |
| 1062 | { |
| 1063 | .burstwords = 256, |
| 1064 | .reg = (PL080_BSIZE_256 << PL080_CONTROL_SB_SIZE_SHIFT) | |
| 1065 | (PL080_BSIZE_256 << PL080_CONTROL_DB_SIZE_SHIFT), |
| 1066 | }, |
| 1067 | { |
| 1068 | .burstwords = 128, |
| 1069 | .reg = (PL080_BSIZE_128 << PL080_CONTROL_SB_SIZE_SHIFT) | |
| 1070 | (PL080_BSIZE_128 << PL080_CONTROL_DB_SIZE_SHIFT), |
| 1071 | }, |
| 1072 | { |
| 1073 | .burstwords = 64, |
| 1074 | .reg = (PL080_BSIZE_64 << PL080_CONTROL_SB_SIZE_SHIFT) | |
| 1075 | (PL080_BSIZE_64 << PL080_CONTROL_DB_SIZE_SHIFT), |
| 1076 | }, |
| 1077 | { |
| 1078 | .burstwords = 32, |
| 1079 | .reg = (PL080_BSIZE_32 << PL080_CONTROL_SB_SIZE_SHIFT) | |
| 1080 | (PL080_BSIZE_32 << PL080_CONTROL_DB_SIZE_SHIFT), |
| 1081 | }, |
| 1082 | { |
| 1083 | .burstwords = 16, |
| 1084 | .reg = (PL080_BSIZE_16 << PL080_CONTROL_SB_SIZE_SHIFT) | |
| 1085 | (PL080_BSIZE_16 << PL080_CONTROL_DB_SIZE_SHIFT), |
| 1086 | }, |
| 1087 | { |
| 1088 | .burstwords = 8, |
| 1089 | .reg = (PL080_BSIZE_8 << PL080_CONTROL_SB_SIZE_SHIFT) | |
| 1090 | (PL080_BSIZE_8 << PL080_CONTROL_DB_SIZE_SHIFT), |
| 1091 | }, |
| 1092 | { |
| 1093 | .burstwords = 4, |
| 1094 | .reg = (PL080_BSIZE_4 << PL080_CONTROL_SB_SIZE_SHIFT) | |
| 1095 | (PL080_BSIZE_4 << PL080_CONTROL_DB_SIZE_SHIFT), |
| 1096 | }, |
| 1097 | { |
| 1098 | .burstwords = 1, |
| 1099 | .reg = (PL080_BSIZE_1 << PL080_CONTROL_SB_SIZE_SHIFT) | |
| 1100 | (PL080_BSIZE_1 << PL080_CONTROL_DB_SIZE_SHIFT), |
| 1101 | }, |
| 1102 | }; |
| 1103 | |
Russell King - ARM Linux | f0fd944 | 2011-01-03 22:45:57 +0000 | [diff] [blame] | 1104 | static int dma_set_runtime_config(struct dma_chan *chan, |
| 1105 | struct dma_slave_config *config) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1106 | { |
| 1107 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1108 | struct pl08x_driver_data *pl08x = plchan->host; |
| 1109 | struct pl08x_channel_data *cd = plchan->cd; |
| 1110 | enum dma_slave_buswidth addr_width; |
Russell King - ARM Linux | f0fd944 | 2011-01-03 22:45:57 +0000 | [diff] [blame] | 1111 | dma_addr_t addr; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1112 | u32 maxburst; |
| 1113 | u32 cctl = 0; |
Russell King - ARM Linux | 4440aac | 2011-01-03 22:30:44 +0000 | [diff] [blame] | 1114 | int i; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1115 | |
Russell King - ARM Linux | b7f7586 | 2011-01-03 22:46:17 +0000 | [diff] [blame] | 1116 | if (!plchan->slave) |
| 1117 | return -EINVAL; |
| 1118 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1119 | /* Transfer direction */ |
| 1120 | plchan->runtime_direction = config->direction; |
| 1121 | if (config->direction == DMA_TO_DEVICE) { |
Russell King - ARM Linux | f0fd944 | 2011-01-03 22:45:57 +0000 | [diff] [blame] | 1122 | addr = config->dst_addr; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1123 | addr_width = config->dst_addr_width; |
| 1124 | maxburst = config->dst_maxburst; |
| 1125 | } else if (config->direction == DMA_FROM_DEVICE) { |
Russell King - ARM Linux | f0fd944 | 2011-01-03 22:45:57 +0000 | [diff] [blame] | 1126 | addr = config->src_addr; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1127 | addr_width = config->src_addr_width; |
| 1128 | maxburst = config->src_maxburst; |
| 1129 | } else { |
| 1130 | dev_err(&pl08x->adev->dev, |
| 1131 | "bad runtime_config: alien transfer direction\n"); |
Russell King - ARM Linux | f0fd944 | 2011-01-03 22:45:57 +0000 | [diff] [blame] | 1132 | return -EINVAL; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | switch (addr_width) { |
| 1136 | case DMA_SLAVE_BUSWIDTH_1_BYTE: |
| 1137 | cctl |= (PL080_WIDTH_8BIT << PL080_CONTROL_SWIDTH_SHIFT) | |
| 1138 | (PL080_WIDTH_8BIT << PL080_CONTROL_DWIDTH_SHIFT); |
| 1139 | break; |
| 1140 | case DMA_SLAVE_BUSWIDTH_2_BYTES: |
| 1141 | cctl |= (PL080_WIDTH_16BIT << PL080_CONTROL_SWIDTH_SHIFT) | |
| 1142 | (PL080_WIDTH_16BIT << PL080_CONTROL_DWIDTH_SHIFT); |
| 1143 | break; |
| 1144 | case DMA_SLAVE_BUSWIDTH_4_BYTES: |
| 1145 | cctl |= (PL080_WIDTH_32BIT << PL080_CONTROL_SWIDTH_SHIFT) | |
| 1146 | (PL080_WIDTH_32BIT << PL080_CONTROL_DWIDTH_SHIFT); |
| 1147 | break; |
| 1148 | default: |
| 1149 | dev_err(&pl08x->adev->dev, |
| 1150 | "bad runtime_config: alien address width\n"); |
Russell King - ARM Linux | f0fd944 | 2011-01-03 22:45:57 +0000 | [diff] [blame] | 1151 | return -EINVAL; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | /* |
| 1155 | * Now decide on a maxburst: |
Russell King - ARM Linux | 4440aac | 2011-01-03 22:30:44 +0000 | [diff] [blame] | 1156 | * If this channel will only request single transfers, set this |
| 1157 | * down to ONE element. Also select one element if no maxburst |
| 1158 | * is specified. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1159 | */ |
Russell King - ARM Linux | 4440aac | 2011-01-03 22:30:44 +0000 | [diff] [blame] | 1160 | if (plchan->cd->single || maxburst == 0) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1161 | cctl |= (PL080_BSIZE_1 << PL080_CONTROL_SB_SIZE_SHIFT) | |
| 1162 | (PL080_BSIZE_1 << PL080_CONTROL_DB_SIZE_SHIFT); |
| 1163 | } else { |
Russell King - ARM Linux | 4440aac | 2011-01-03 22:30:44 +0000 | [diff] [blame] | 1164 | for (i = 0; i < ARRAY_SIZE(burst_sizes); i++) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1165 | if (burst_sizes[i].burstwords <= maxburst) |
| 1166 | break; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1167 | cctl |= burst_sizes[i].reg; |
| 1168 | } |
| 1169 | |
Russell King - ARM Linux | f0fd944 | 2011-01-03 22:45:57 +0000 | [diff] [blame] | 1170 | plchan->runtime_addr = addr; |
| 1171 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1172 | /* Modify the default channel data to fit PrimeCell request */ |
| 1173 | cd->cctl = cctl; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1174 | |
| 1175 | dev_dbg(&pl08x->adev->dev, |
| 1176 | "configured channel %s (%s) for %s, data width %d, " |
Russell King - ARM Linux | 4983a04 | 2011-01-03 22:39:33 +0000 | [diff] [blame] | 1177 | "maxburst %d words, LE, CCTL=0x%08x\n", |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1178 | dma_chan_name(chan), plchan->name, |
| 1179 | (config->direction == DMA_FROM_DEVICE) ? "RX" : "TX", |
| 1180 | addr_width, |
| 1181 | maxburst, |
Russell King - ARM Linux | 4983a04 | 2011-01-03 22:39:33 +0000 | [diff] [blame] | 1182 | cctl); |
Russell King - ARM Linux | f0fd944 | 2011-01-03 22:45:57 +0000 | [diff] [blame] | 1183 | |
| 1184 | return 0; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | /* |
| 1188 | * Slave transactions callback to the slave device to allow |
| 1189 | * synchronization of slave DMA signals with the DMAC enable |
| 1190 | */ |
| 1191 | static void pl08x_issue_pending(struct dma_chan *chan) |
| 1192 | { |
| 1193 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1194 | unsigned long flags; |
| 1195 | |
| 1196 | spin_lock_irqsave(&plchan->lock, flags); |
Russell King - ARM Linux | 9c0bb43 | 2011-01-03 22:32:05 +0000 | [diff] [blame] | 1197 | /* Something is already active, or we're waiting for a channel... */ |
| 1198 | if (plchan->at || plchan->state == PL08X_CHAN_WAITING) { |
| 1199 | spin_unlock_irqrestore(&plchan->lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1200 | return; |
Russell King - ARM Linux | 9c0bb43 | 2011-01-03 22:32:05 +0000 | [diff] [blame] | 1201 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1202 | |
| 1203 | /* Take the first element in the queue and execute it */ |
Russell King - ARM Linux | 15c1723 | 2011-01-03 22:44:36 +0000 | [diff] [blame] | 1204 | if (!list_empty(&plchan->pend_list)) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1205 | struct pl08x_txd *next; |
| 1206 | |
Russell King - ARM Linux | 15c1723 | 2011-01-03 22:44:36 +0000 | [diff] [blame] | 1207 | next = list_first_entry(&plchan->pend_list, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1208 | struct pl08x_txd, |
| 1209 | node); |
| 1210 | list_del(&next->node); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1211 | plchan->state = PL08X_CHAN_RUNNING; |
| 1212 | |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 1213 | pl08x_start_txd(plchan, next); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | spin_unlock_irqrestore(&plchan->lock, flags); |
| 1217 | } |
| 1218 | |
| 1219 | static int pl08x_prep_channel_resources(struct pl08x_dma_chan *plchan, |
| 1220 | struct pl08x_txd *txd) |
| 1221 | { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1222 | struct pl08x_driver_data *pl08x = plchan->host; |
Russell King - ARM Linux | c370e59 | 2011-01-03 22:45:37 +0000 | [diff] [blame] | 1223 | unsigned long flags; |
| 1224 | int num_llis, ret; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1225 | |
| 1226 | num_llis = pl08x_fill_llis_for_desc(pl08x, txd); |
Russell King - ARM Linux | dafa731 | 2011-01-03 22:31:45 +0000 | [diff] [blame] | 1227 | if (!num_llis) { |
| 1228 | kfree(txd); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1229 | return -EINVAL; |
Russell King - ARM Linux | dafa731 | 2011-01-03 22:31:45 +0000 | [diff] [blame] | 1230 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1231 | |
Russell King - ARM Linux | c370e59 | 2011-01-03 22:45:37 +0000 | [diff] [blame] | 1232 | spin_lock_irqsave(&plchan->lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1233 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1234 | /* |
| 1235 | * See if we already have a physical channel allocated, |
| 1236 | * else this is the time to try to get one. |
| 1237 | */ |
| 1238 | ret = prep_phy_channel(plchan, txd); |
| 1239 | if (ret) { |
| 1240 | /* |
Russell King - ARM Linux | 501e67e | 2011-01-03 22:44:57 +0000 | [diff] [blame] | 1241 | * No physical channel was available. |
| 1242 | * |
| 1243 | * memcpy transfers can be sorted out at submission time. |
| 1244 | * |
| 1245 | * Slave transfers may have been denied due to platform |
| 1246 | * channel muxing restrictions. Since there is no guarantee |
| 1247 | * that this will ever be resolved, and the signal must be |
| 1248 | * acquired AFTER acquiring the physical channel, we will let |
| 1249 | * them be NACK:ed with -EBUSY here. The drivers can retry |
| 1250 | * the prep() call if they are eager on doing this using DMA. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1251 | */ |
| 1252 | if (plchan->slave) { |
| 1253 | pl08x_free_txd_list(pl08x, plchan); |
Russell King - ARM Linux | 501e67e | 2011-01-03 22:44:57 +0000 | [diff] [blame] | 1254 | pl08x_free_txd(pl08x, txd); |
Russell King - ARM Linux | c370e59 | 2011-01-03 22:45:37 +0000 | [diff] [blame] | 1255 | spin_unlock_irqrestore(&plchan->lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1256 | return -EBUSY; |
| 1257 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1258 | } else |
| 1259 | /* |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1260 | * Else we're all set, paused and ready to roll, status |
| 1261 | * will switch to PL08X_CHAN_RUNNING when we call |
| 1262 | * issue_pending(). If there is something running on the |
| 1263 | * channel already we don't change its state. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1264 | */ |
| 1265 | if (plchan->state == PL08X_CHAN_IDLE) |
| 1266 | plchan->state = PL08X_CHAN_PAUSED; |
| 1267 | |
Russell King - ARM Linux | c370e59 | 2011-01-03 22:45:37 +0000 | [diff] [blame] | 1268 | spin_unlock_irqrestore(&plchan->lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 1273 | /* |
| 1274 | * Given the source and destination available bus masks, select which |
| 1275 | * will be routed to each port. We try to have source and destination |
| 1276 | * on separate ports, but always respect the allowable settings. |
| 1277 | */ |
| 1278 | static u32 pl08x_select_bus(struct pl08x_driver_data *pl08x, u8 src, u8 dst) |
| 1279 | { |
| 1280 | u32 cctl = 0; |
| 1281 | |
| 1282 | if (!(dst & PL08X_AHB1) || ((dst & PL08X_AHB2) && (src & PL08X_AHB1))) |
| 1283 | cctl |= PL080_CONTROL_DST_AHB2; |
| 1284 | if (!(src & PL08X_AHB1) || ((src & PL08X_AHB2) && !(dst & PL08X_AHB2))) |
| 1285 | cctl |= PL080_CONTROL_SRC_AHB2; |
| 1286 | |
| 1287 | return cctl; |
| 1288 | } |
| 1289 | |
Russell King - ARM Linux | c042879 | 2011-01-03 22:43:56 +0000 | [diff] [blame] | 1290 | static struct pl08x_txd *pl08x_get_txd(struct pl08x_dma_chan *plchan, |
| 1291 | unsigned long flags) |
Russell King - ARM Linux | ac3cd20 | 2011-01-03 22:35:49 +0000 | [diff] [blame] | 1292 | { |
| 1293 | struct pl08x_txd *txd = kzalloc(sizeof(struct pl08x_txd), GFP_NOWAIT); |
| 1294 | |
| 1295 | if (txd) { |
| 1296 | dma_async_tx_descriptor_init(&txd->tx, &plchan->chan); |
Russell King - ARM Linux | c042879 | 2011-01-03 22:43:56 +0000 | [diff] [blame] | 1297 | txd->tx.flags = flags; |
Russell King - ARM Linux | ac3cd20 | 2011-01-03 22:35:49 +0000 | [diff] [blame] | 1298 | txd->tx.tx_submit = pl08x_tx_submit; |
| 1299 | INIT_LIST_HEAD(&txd->node); |
Russell King - ARM Linux | 4983a04 | 2011-01-03 22:39:33 +0000 | [diff] [blame] | 1300 | |
| 1301 | /* Always enable error and terminal interrupts */ |
| 1302 | txd->ccfg = PL080_CONFIG_ERR_IRQ_MASK | |
| 1303 | PL080_CONFIG_TC_IRQ_MASK; |
Russell King - ARM Linux | ac3cd20 | 2011-01-03 22:35:49 +0000 | [diff] [blame] | 1304 | } |
| 1305 | return txd; |
| 1306 | } |
| 1307 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1308 | /* |
| 1309 | * Initialize a descriptor to be used by memcpy submit |
| 1310 | */ |
| 1311 | static struct dma_async_tx_descriptor *pl08x_prep_dma_memcpy( |
| 1312 | struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, |
| 1313 | size_t len, unsigned long flags) |
| 1314 | { |
| 1315 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1316 | struct pl08x_driver_data *pl08x = plchan->host; |
| 1317 | struct pl08x_txd *txd; |
| 1318 | int ret; |
| 1319 | |
Russell King - ARM Linux | c042879 | 2011-01-03 22:43:56 +0000 | [diff] [blame] | 1320 | txd = pl08x_get_txd(plchan, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1321 | if (!txd) { |
| 1322 | dev_err(&pl08x->adev->dev, |
| 1323 | "%s no memory for descriptor\n", __func__); |
| 1324 | return NULL; |
| 1325 | } |
| 1326 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1327 | txd->direction = DMA_NONE; |
Russell King - ARM Linux | d7244e9 | 2011-01-03 22:43:35 +0000 | [diff] [blame] | 1328 | txd->src_addr = src; |
| 1329 | txd->dst_addr = dest; |
Russell King - ARM Linux | c7da9a5 | 2011-01-03 22:40:53 +0000 | [diff] [blame] | 1330 | txd->len = len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1331 | |
| 1332 | /* Set platform data for m2m */ |
Russell King - ARM Linux | 4983a04 | 2011-01-03 22:39:33 +0000 | [diff] [blame] | 1333 | txd->ccfg |= PL080_FLOW_MEM2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT; |
Russell King - ARM Linux | c7da9a5 | 2011-01-03 22:40:53 +0000 | [diff] [blame] | 1334 | txd->cctl = pl08x->pd->memcpy_channel.cctl & |
| 1335 | ~(PL080_CONTROL_DST_AHB2 | PL080_CONTROL_SRC_AHB2); |
Russell King - ARM Linux | 4983a04 | 2011-01-03 22:39:33 +0000 | [diff] [blame] | 1336 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1337 | /* Both to be incremented or the code will break */ |
Russell King - ARM Linux | 70b5ed6 | 2011-01-03 22:40:13 +0000 | [diff] [blame] | 1338 | txd->cctl |= PL080_CONTROL_SRC_INCR | PL080_CONTROL_DST_INCR; |
Russell King - ARM Linux | c7da9a5 | 2011-01-03 22:40:53 +0000 | [diff] [blame] | 1339 | |
Russell King - ARM Linux | c7da9a5 | 2011-01-03 22:40:53 +0000 | [diff] [blame] | 1340 | if (pl08x->vd->dualmaster) |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 1341 | txd->cctl |= pl08x_select_bus(pl08x, |
| 1342 | pl08x->mem_buses, pl08x->mem_buses); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1343 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1344 | ret = pl08x_prep_channel_resources(plchan, txd); |
| 1345 | if (ret) |
| 1346 | return NULL; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1347 | |
| 1348 | return &txd->tx; |
| 1349 | } |
| 1350 | |
Russell King - ARM Linux | 3e2a037 | 2011-01-03 22:32:46 +0000 | [diff] [blame] | 1351 | static struct dma_async_tx_descriptor *pl08x_prep_slave_sg( |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1352 | struct dma_chan *chan, struct scatterlist *sgl, |
| 1353 | unsigned int sg_len, enum dma_data_direction direction, |
| 1354 | unsigned long flags) |
| 1355 | { |
| 1356 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1357 | struct pl08x_driver_data *pl08x = plchan->host; |
| 1358 | struct pl08x_txd *txd; |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 1359 | u8 src_buses, dst_buses; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1360 | int ret; |
| 1361 | |
| 1362 | /* |
| 1363 | * Current implementation ASSUMES only one sg |
| 1364 | */ |
| 1365 | if (sg_len != 1) { |
| 1366 | dev_err(&pl08x->adev->dev, "%s prepared too long sglist\n", |
| 1367 | __func__); |
| 1368 | BUG(); |
| 1369 | } |
| 1370 | |
| 1371 | dev_dbg(&pl08x->adev->dev, "%s prepare transaction of %d bytes from %s\n", |
| 1372 | __func__, sgl->length, plchan->name); |
| 1373 | |
Russell King - ARM Linux | c042879 | 2011-01-03 22:43:56 +0000 | [diff] [blame] | 1374 | txd = pl08x_get_txd(plchan, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1375 | if (!txd) { |
| 1376 | dev_err(&pl08x->adev->dev, "%s no txd\n", __func__); |
| 1377 | return NULL; |
| 1378 | } |
| 1379 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1380 | if (direction != plchan->runtime_direction) |
| 1381 | dev_err(&pl08x->adev->dev, "%s DMA setup does not match " |
| 1382 | "the direction configured for the PrimeCell\n", |
| 1383 | __func__); |
| 1384 | |
| 1385 | /* |
| 1386 | * Set up addresses, the PrimeCell configured address |
| 1387 | * will take precedence since this may configure the |
| 1388 | * channel target address dynamically at runtime. |
| 1389 | */ |
| 1390 | txd->direction = direction; |
Russell King - ARM Linux | c7da9a5 | 2011-01-03 22:40:53 +0000 | [diff] [blame] | 1391 | txd->len = sgl->length; |
| 1392 | |
Russell King - ARM Linux | 1cae78f | 2011-01-03 22:40:33 +0000 | [diff] [blame] | 1393 | txd->cctl = plchan->cd->cctl & |
Russell King - ARM Linux | c7da9a5 | 2011-01-03 22:40:53 +0000 | [diff] [blame] | 1394 | ~(PL080_CONTROL_SRC_AHB2 | PL080_CONTROL_DST_AHB2 | |
| 1395 | PL080_CONTROL_SRC_INCR | PL080_CONTROL_DST_INCR | |
Russell King - ARM Linux | 1cae78f | 2011-01-03 22:40:33 +0000 | [diff] [blame] | 1396 | PL080_CONTROL_PROT_MASK); |
| 1397 | |
| 1398 | /* Access the cell in privileged mode, non-bufferable, non-cacheable */ |
| 1399 | txd->cctl |= PL080_CONTROL_PROT_SYS; |
Russell King - ARM Linux | 70b5ed6 | 2011-01-03 22:40:13 +0000 | [diff] [blame] | 1400 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1401 | if (direction == DMA_TO_DEVICE) { |
Russell King - ARM Linux | 4983a04 | 2011-01-03 22:39:33 +0000 | [diff] [blame] | 1402 | txd->ccfg |= PL080_FLOW_MEM2PER << PL080_CONFIG_FLOW_CONTROL_SHIFT; |
Russell King - ARM Linux | 1cae78f | 2011-01-03 22:40:33 +0000 | [diff] [blame] | 1403 | txd->cctl |= PL080_CONTROL_SRC_INCR; |
Russell King - ARM Linux | d7244e9 | 2011-01-03 22:43:35 +0000 | [diff] [blame] | 1404 | txd->src_addr = sgl->dma_address; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1405 | if (plchan->runtime_addr) |
Russell King - ARM Linux | d7244e9 | 2011-01-03 22:43:35 +0000 | [diff] [blame] | 1406 | txd->dst_addr = plchan->runtime_addr; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1407 | else |
Russell King - ARM Linux | d7244e9 | 2011-01-03 22:43:35 +0000 | [diff] [blame] | 1408 | txd->dst_addr = plchan->cd->addr; |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 1409 | src_buses = pl08x->mem_buses; |
| 1410 | dst_buses = plchan->cd->periph_buses; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1411 | } else if (direction == DMA_FROM_DEVICE) { |
Russell King - ARM Linux | 4983a04 | 2011-01-03 22:39:33 +0000 | [diff] [blame] | 1412 | txd->ccfg |= PL080_FLOW_PER2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT; |
Russell King - ARM Linux | 1cae78f | 2011-01-03 22:40:33 +0000 | [diff] [blame] | 1413 | txd->cctl |= PL080_CONTROL_DST_INCR; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1414 | if (plchan->runtime_addr) |
Russell King - ARM Linux | d7244e9 | 2011-01-03 22:43:35 +0000 | [diff] [blame] | 1415 | txd->src_addr = plchan->runtime_addr; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1416 | else |
Russell King - ARM Linux | d7244e9 | 2011-01-03 22:43:35 +0000 | [diff] [blame] | 1417 | txd->src_addr = plchan->cd->addr; |
| 1418 | txd->dst_addr = sgl->dma_address; |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 1419 | src_buses = plchan->cd->periph_buses; |
| 1420 | dst_buses = pl08x->mem_buses; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1421 | } else { |
| 1422 | dev_err(&pl08x->adev->dev, |
| 1423 | "%s direction unsupported\n", __func__); |
| 1424 | return NULL; |
| 1425 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1426 | |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 1427 | txd->cctl |= pl08x_select_bus(pl08x, src_buses, dst_buses); |
| 1428 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1429 | ret = pl08x_prep_channel_resources(plchan, txd); |
| 1430 | if (ret) |
| 1431 | return NULL; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1432 | |
| 1433 | return &txd->tx; |
| 1434 | } |
| 1435 | |
| 1436 | static int pl08x_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, |
| 1437 | unsigned long arg) |
| 1438 | { |
| 1439 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1440 | struct pl08x_driver_data *pl08x = plchan->host; |
| 1441 | unsigned long flags; |
| 1442 | int ret = 0; |
| 1443 | |
| 1444 | /* Controls applicable to inactive channels */ |
| 1445 | if (cmd == DMA_SLAVE_CONFIG) { |
Russell King - ARM Linux | f0fd944 | 2011-01-03 22:45:57 +0000 | [diff] [blame] | 1446 | return dma_set_runtime_config(chan, |
| 1447 | (struct dma_slave_config *)arg); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | /* |
| 1451 | * Anything succeeds on channels with no physical allocation and |
| 1452 | * no queued transfers. |
| 1453 | */ |
| 1454 | spin_lock_irqsave(&plchan->lock, flags); |
| 1455 | if (!plchan->phychan && !plchan->at) { |
| 1456 | spin_unlock_irqrestore(&plchan->lock, flags); |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
| 1460 | switch (cmd) { |
| 1461 | case DMA_TERMINATE_ALL: |
| 1462 | plchan->state = PL08X_CHAN_IDLE; |
| 1463 | |
| 1464 | if (plchan->phychan) { |
Russell King - ARM Linux | fb52621 | 2011-01-27 12:32:53 +0000 | [diff] [blame] | 1465 | pl08x_terminate_phy_chan(pl08x, plchan->phychan); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1466 | |
| 1467 | /* |
| 1468 | * Mark physical channel as free and free any slave |
| 1469 | * signal |
| 1470 | */ |
Russell King - ARM Linux | 8c8cc2b | 2011-01-03 22:36:09 +0000 | [diff] [blame] | 1471 | release_phy_channel(plchan); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1472 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1473 | /* Dequeue jobs and free LLIs */ |
| 1474 | if (plchan->at) { |
| 1475 | pl08x_free_txd(pl08x, plchan->at); |
| 1476 | plchan->at = NULL; |
| 1477 | } |
| 1478 | /* Dequeue jobs not yet fired as well */ |
| 1479 | pl08x_free_txd_list(pl08x, plchan); |
| 1480 | break; |
| 1481 | case DMA_PAUSE: |
| 1482 | pl08x_pause_phy_chan(plchan->phychan); |
| 1483 | plchan->state = PL08X_CHAN_PAUSED; |
| 1484 | break; |
| 1485 | case DMA_RESUME: |
| 1486 | pl08x_resume_phy_chan(plchan->phychan); |
| 1487 | plchan->state = PL08X_CHAN_RUNNING; |
| 1488 | break; |
| 1489 | default: |
| 1490 | /* Unknown command */ |
| 1491 | ret = -ENXIO; |
| 1492 | break; |
| 1493 | } |
| 1494 | |
| 1495 | spin_unlock_irqrestore(&plchan->lock, flags); |
| 1496 | |
| 1497 | return ret; |
| 1498 | } |
| 1499 | |
| 1500 | bool pl08x_filter_id(struct dma_chan *chan, void *chan_id) |
| 1501 | { |
| 1502 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1503 | char *name = chan_id; |
| 1504 | |
| 1505 | /* Check that the channel is not taken! */ |
| 1506 | if (!strcmp(plchan->name, name)) |
| 1507 | return true; |
| 1508 | |
| 1509 | return false; |
| 1510 | } |
| 1511 | |
| 1512 | /* |
| 1513 | * Just check that the device is there and active |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1514 | * TODO: turn this bit on/off depending on the number of physical channels |
| 1515 | * actually used, if it is zero... well shut it off. That will save some |
| 1516 | * power. Cut the clock at the same time. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1517 | */ |
| 1518 | static void pl08x_ensure_on(struct pl08x_driver_data *pl08x) |
| 1519 | { |
| 1520 | u32 val; |
| 1521 | |
| 1522 | val = readl(pl08x->base + PL080_CONFIG); |
| 1523 | val &= ~(PL080_CONFIG_M2_BE | PL080_CONFIG_M1_BE | PL080_CONFIG_ENABLE); |
Russell King - ARM Linux | e8b5e11 | 2011-01-03 22:30:24 +0000 | [diff] [blame] | 1524 | /* We implicitly clear bit 1 and that means little-endian mode */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1525 | val |= PL080_CONFIG_ENABLE; |
| 1526 | writel(val, pl08x->base + PL080_CONFIG); |
| 1527 | } |
| 1528 | |
Russell King - ARM Linux | 3d992e1 | 2011-01-03 22:44:16 +0000 | [diff] [blame] | 1529 | static void pl08x_unmap_buffers(struct pl08x_txd *txd) |
| 1530 | { |
| 1531 | struct device *dev = txd->tx.chan->device->dev; |
| 1532 | |
| 1533 | if (!(txd->tx.flags & DMA_COMPL_SKIP_SRC_UNMAP)) { |
| 1534 | if (txd->tx.flags & DMA_COMPL_SRC_UNMAP_SINGLE) |
| 1535 | dma_unmap_single(dev, txd->src_addr, txd->len, |
| 1536 | DMA_TO_DEVICE); |
| 1537 | else |
| 1538 | dma_unmap_page(dev, txd->src_addr, txd->len, |
| 1539 | DMA_TO_DEVICE); |
| 1540 | } |
| 1541 | if (!(txd->tx.flags & DMA_COMPL_SKIP_DEST_UNMAP)) { |
| 1542 | if (txd->tx.flags & DMA_COMPL_DEST_UNMAP_SINGLE) |
| 1543 | dma_unmap_single(dev, txd->dst_addr, txd->len, |
| 1544 | DMA_FROM_DEVICE); |
| 1545 | else |
| 1546 | dma_unmap_page(dev, txd->dst_addr, txd->len, |
| 1547 | DMA_FROM_DEVICE); |
| 1548 | } |
| 1549 | } |
| 1550 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1551 | static void pl08x_tasklet(unsigned long data) |
| 1552 | { |
| 1553 | struct pl08x_dma_chan *plchan = (struct pl08x_dma_chan *) data; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1554 | struct pl08x_driver_data *pl08x = plchan->host; |
Russell King - ARM Linux | 858c21c | 2011-01-03 22:41:34 +0000 | [diff] [blame] | 1555 | struct pl08x_txd *txd; |
Russell King - ARM Linux | bf072af | 2011-01-03 22:31:24 +0000 | [diff] [blame] | 1556 | unsigned long flags; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1557 | |
Russell King - ARM Linux | bf072af | 2011-01-03 22:31:24 +0000 | [diff] [blame] | 1558 | spin_lock_irqsave(&plchan->lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1559 | |
Russell King - ARM Linux | 858c21c | 2011-01-03 22:41:34 +0000 | [diff] [blame] | 1560 | txd = plchan->at; |
| 1561 | plchan->at = NULL; |
| 1562 | |
| 1563 | if (txd) { |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1564 | /* Update last completed */ |
Russell King - ARM Linux | 858c21c | 2011-01-03 22:41:34 +0000 | [diff] [blame] | 1565 | plchan->lc = txd->tx.cookie; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1566 | } |
Russell King - ARM Linux | 8087aac | 2011-01-03 22:45:17 +0000 | [diff] [blame] | 1567 | |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1568 | /* If a new descriptor is queued, set it up plchan->at is NULL here */ |
Russell King - ARM Linux | 15c1723 | 2011-01-03 22:44:36 +0000 | [diff] [blame] | 1569 | if (!list_empty(&plchan->pend_list)) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1570 | struct pl08x_txd *next; |
| 1571 | |
Russell King - ARM Linux | 15c1723 | 2011-01-03 22:44:36 +0000 | [diff] [blame] | 1572 | next = list_first_entry(&plchan->pend_list, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1573 | struct pl08x_txd, |
| 1574 | node); |
| 1575 | list_del(&next->node); |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 1576 | |
| 1577 | pl08x_start_txd(plchan, next); |
Russell King - ARM Linux | 8087aac | 2011-01-03 22:45:17 +0000 | [diff] [blame] | 1578 | } else if (plchan->phychan_hold) { |
| 1579 | /* |
| 1580 | * This channel is still in use - we have a new txd being |
| 1581 | * prepared and will soon be queued. Don't give up the |
| 1582 | * physical channel. |
| 1583 | */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1584 | } else { |
| 1585 | struct pl08x_dma_chan *waiting = NULL; |
| 1586 | |
| 1587 | /* |
| 1588 | * No more jobs, so free up the physical channel |
| 1589 | * Free any allocated signal on slave transfers too |
| 1590 | */ |
Russell King - ARM Linux | 8c8cc2b | 2011-01-03 22:36:09 +0000 | [diff] [blame] | 1591 | release_phy_channel(plchan); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1592 | plchan->state = PL08X_CHAN_IDLE; |
| 1593 | |
| 1594 | /* |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1595 | * And NOW before anyone else can grab that free:d up |
| 1596 | * physical channel, see if there is some memcpy pending |
| 1597 | * that seriously needs to start because of being stacked |
| 1598 | * up while we were choking the physical channels with data. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1599 | */ |
| 1600 | list_for_each_entry(waiting, &pl08x->memcpy.channels, |
| 1601 | chan.device_node) { |
| 1602 | if (waiting->state == PL08X_CHAN_WAITING && |
| 1603 | waiting->waiting != NULL) { |
| 1604 | int ret; |
| 1605 | |
| 1606 | /* This should REALLY not fail now */ |
| 1607 | ret = prep_phy_channel(waiting, |
| 1608 | waiting->waiting); |
| 1609 | BUG_ON(ret); |
Russell King - ARM Linux | 8087aac | 2011-01-03 22:45:17 +0000 | [diff] [blame] | 1610 | waiting->phychan_hold--; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1611 | waiting->state = PL08X_CHAN_RUNNING; |
| 1612 | waiting->waiting = NULL; |
| 1613 | pl08x_issue_pending(&waiting->chan); |
| 1614 | break; |
| 1615 | } |
| 1616 | } |
| 1617 | } |
| 1618 | |
Russell King - ARM Linux | bf072af | 2011-01-03 22:31:24 +0000 | [diff] [blame] | 1619 | spin_unlock_irqrestore(&plchan->lock, flags); |
Russell King - ARM Linux | 858c21c | 2011-01-03 22:41:34 +0000 | [diff] [blame] | 1620 | |
Russell King - ARM Linux | 3d992e1 | 2011-01-03 22:44:16 +0000 | [diff] [blame] | 1621 | if (txd) { |
| 1622 | dma_async_tx_callback callback = txd->tx.callback; |
| 1623 | void *callback_param = txd->tx.callback_param; |
| 1624 | |
| 1625 | /* Don't try to unmap buffers on slave channels */ |
| 1626 | if (!plchan->slave) |
| 1627 | pl08x_unmap_buffers(txd); |
| 1628 | |
| 1629 | /* Free the descriptor */ |
| 1630 | spin_lock_irqsave(&plchan->lock, flags); |
| 1631 | pl08x_free_txd(pl08x, txd); |
| 1632 | spin_unlock_irqrestore(&plchan->lock, flags); |
| 1633 | |
| 1634 | /* Callback to signal completion */ |
| 1635 | if (callback) |
| 1636 | callback(callback_param); |
| 1637 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | static irqreturn_t pl08x_irq(int irq, void *dev) |
| 1641 | { |
| 1642 | struct pl08x_driver_data *pl08x = dev; |
| 1643 | u32 mask = 0; |
| 1644 | u32 val; |
| 1645 | int i; |
| 1646 | |
| 1647 | val = readl(pl08x->base + PL080_ERR_STATUS); |
| 1648 | if (val) { |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1649 | /* An error interrupt (on one or more channels) */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1650 | dev_err(&pl08x->adev->dev, |
| 1651 | "%s error interrupt, register value 0x%08x\n", |
| 1652 | __func__, val); |
| 1653 | /* |
| 1654 | * Simply clear ALL PL08X error interrupts, |
| 1655 | * regardless of channel and cause |
| 1656 | * FIXME: should be 0x00000003 on PL081 really. |
| 1657 | */ |
| 1658 | writel(0x000000FF, pl08x->base + PL080_ERR_CLEAR); |
| 1659 | } |
| 1660 | val = readl(pl08x->base + PL080_INT_STATUS); |
| 1661 | for (i = 0; i < pl08x->vd->channels; i++) { |
| 1662 | if ((1 << i) & val) { |
| 1663 | /* Locate physical channel */ |
| 1664 | struct pl08x_phy_chan *phychan = &pl08x->phy_chans[i]; |
| 1665 | struct pl08x_dma_chan *plchan = phychan->serving; |
| 1666 | |
| 1667 | /* Schedule tasklet on this channel */ |
| 1668 | tasklet_schedule(&plchan->tasklet); |
| 1669 | |
| 1670 | mask |= (1 << i); |
| 1671 | } |
| 1672 | } |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1673 | /* Clear only the terminal interrupts on channels we processed */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1674 | writel(mask, pl08x->base + PL080_TC_CLEAR); |
| 1675 | |
| 1676 | return mask ? IRQ_HANDLED : IRQ_NONE; |
| 1677 | } |
| 1678 | |
| 1679 | /* |
| 1680 | * Initialise the DMAC memcpy/slave channels. |
| 1681 | * Make a local wrapper to hold required data |
| 1682 | */ |
| 1683 | static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x, |
| 1684 | struct dma_device *dmadev, |
| 1685 | unsigned int channels, |
| 1686 | bool slave) |
| 1687 | { |
| 1688 | struct pl08x_dma_chan *chan; |
| 1689 | int i; |
| 1690 | |
| 1691 | INIT_LIST_HEAD(&dmadev->channels); |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1692 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1693 | /* |
| 1694 | * Register as many many memcpy as we have physical channels, |
| 1695 | * we won't always be able to use all but the code will have |
| 1696 | * to cope with that situation. |
| 1697 | */ |
| 1698 | for (i = 0; i < channels; i++) { |
| 1699 | chan = kzalloc(sizeof(struct pl08x_dma_chan), GFP_KERNEL); |
| 1700 | if (!chan) { |
| 1701 | dev_err(&pl08x->adev->dev, |
| 1702 | "%s no memory for channel\n", __func__); |
| 1703 | return -ENOMEM; |
| 1704 | } |
| 1705 | |
| 1706 | chan->host = pl08x; |
| 1707 | chan->state = PL08X_CHAN_IDLE; |
| 1708 | |
| 1709 | if (slave) { |
| 1710 | chan->slave = true; |
| 1711 | chan->name = pl08x->pd->slave_channels[i].bus_id; |
| 1712 | chan->cd = &pl08x->pd->slave_channels[i]; |
| 1713 | } else { |
| 1714 | chan->cd = &pl08x->pd->memcpy_channel; |
| 1715 | chan->name = kasprintf(GFP_KERNEL, "memcpy%d", i); |
| 1716 | if (!chan->name) { |
| 1717 | kfree(chan); |
| 1718 | return -ENOMEM; |
| 1719 | } |
| 1720 | } |
Russell King - ARM Linux | b58b6b5 | 2011-01-03 22:34:48 +0000 | [diff] [blame] | 1721 | if (chan->cd->circular_buffer) { |
| 1722 | dev_err(&pl08x->adev->dev, |
| 1723 | "channel %s: circular buffers not supported\n", |
| 1724 | chan->name); |
| 1725 | kfree(chan); |
| 1726 | continue; |
| 1727 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1728 | dev_info(&pl08x->adev->dev, |
| 1729 | "initialize virtual channel \"%s\"\n", |
| 1730 | chan->name); |
| 1731 | |
| 1732 | chan->chan.device = dmadev; |
Russell King - ARM Linux | 91aa5fa | 2011-01-03 22:31:04 +0000 | [diff] [blame] | 1733 | chan->chan.cookie = 0; |
| 1734 | chan->lc = 0; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1735 | |
| 1736 | spin_lock_init(&chan->lock); |
Russell King - ARM Linux | 15c1723 | 2011-01-03 22:44:36 +0000 | [diff] [blame] | 1737 | INIT_LIST_HEAD(&chan->pend_list); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1738 | tasklet_init(&chan->tasklet, pl08x_tasklet, |
| 1739 | (unsigned long) chan); |
| 1740 | |
| 1741 | list_add_tail(&chan->chan.device_node, &dmadev->channels); |
| 1742 | } |
| 1743 | dev_info(&pl08x->adev->dev, "initialized %d virtual %s channels\n", |
| 1744 | i, slave ? "slave" : "memcpy"); |
| 1745 | return i; |
| 1746 | } |
| 1747 | |
| 1748 | static void pl08x_free_virtual_channels(struct dma_device *dmadev) |
| 1749 | { |
| 1750 | struct pl08x_dma_chan *chan = NULL; |
| 1751 | struct pl08x_dma_chan *next; |
| 1752 | |
| 1753 | list_for_each_entry_safe(chan, |
| 1754 | next, &dmadev->channels, chan.device_node) { |
| 1755 | list_del(&chan->chan.device_node); |
| 1756 | kfree(chan); |
| 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | #ifdef CONFIG_DEBUG_FS |
| 1761 | static const char *pl08x_state_str(enum pl08x_dma_chan_state state) |
| 1762 | { |
| 1763 | switch (state) { |
| 1764 | case PL08X_CHAN_IDLE: |
| 1765 | return "idle"; |
| 1766 | case PL08X_CHAN_RUNNING: |
| 1767 | return "running"; |
| 1768 | case PL08X_CHAN_PAUSED: |
| 1769 | return "paused"; |
| 1770 | case PL08X_CHAN_WAITING: |
| 1771 | return "waiting"; |
| 1772 | default: |
| 1773 | break; |
| 1774 | } |
| 1775 | return "UNKNOWN STATE"; |
| 1776 | } |
| 1777 | |
| 1778 | static int pl08x_debugfs_show(struct seq_file *s, void *data) |
| 1779 | { |
| 1780 | struct pl08x_driver_data *pl08x = s->private; |
| 1781 | struct pl08x_dma_chan *chan; |
| 1782 | struct pl08x_phy_chan *ch; |
| 1783 | unsigned long flags; |
| 1784 | int i; |
| 1785 | |
| 1786 | seq_printf(s, "PL08x physical channels:\n"); |
| 1787 | seq_printf(s, "CHANNEL:\tUSER:\n"); |
| 1788 | seq_printf(s, "--------\t-----\n"); |
| 1789 | for (i = 0; i < pl08x->vd->channels; i++) { |
| 1790 | struct pl08x_dma_chan *virt_chan; |
| 1791 | |
| 1792 | ch = &pl08x->phy_chans[i]; |
| 1793 | |
| 1794 | spin_lock_irqsave(&ch->lock, flags); |
| 1795 | virt_chan = ch->serving; |
| 1796 | |
| 1797 | seq_printf(s, "%d\t\t%s\n", |
| 1798 | ch->id, virt_chan ? virt_chan->name : "(none)"); |
| 1799 | |
| 1800 | spin_unlock_irqrestore(&ch->lock, flags); |
| 1801 | } |
| 1802 | |
| 1803 | seq_printf(s, "\nPL08x virtual memcpy channels:\n"); |
| 1804 | seq_printf(s, "CHANNEL:\tSTATE:\n"); |
| 1805 | seq_printf(s, "--------\t------\n"); |
| 1806 | list_for_each_entry(chan, &pl08x->memcpy.channels, chan.device_node) { |
Russell King - ARM Linux | 3e2a037 | 2011-01-03 22:32:46 +0000 | [diff] [blame] | 1807 | seq_printf(s, "%s\t\t%s\n", chan->name, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1808 | pl08x_state_str(chan->state)); |
| 1809 | } |
| 1810 | |
| 1811 | seq_printf(s, "\nPL08x virtual slave channels:\n"); |
| 1812 | seq_printf(s, "CHANNEL:\tSTATE:\n"); |
| 1813 | seq_printf(s, "--------\t------\n"); |
| 1814 | list_for_each_entry(chan, &pl08x->slave.channels, chan.device_node) { |
Russell King - ARM Linux | 3e2a037 | 2011-01-03 22:32:46 +0000 | [diff] [blame] | 1815 | seq_printf(s, "%s\t\t%s\n", chan->name, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1816 | pl08x_state_str(chan->state)); |
| 1817 | } |
| 1818 | |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
| 1822 | static int pl08x_debugfs_open(struct inode *inode, struct file *file) |
| 1823 | { |
| 1824 | return single_open(file, pl08x_debugfs_show, inode->i_private); |
| 1825 | } |
| 1826 | |
| 1827 | static const struct file_operations pl08x_debugfs_operations = { |
| 1828 | .open = pl08x_debugfs_open, |
| 1829 | .read = seq_read, |
| 1830 | .llseek = seq_lseek, |
| 1831 | .release = single_release, |
| 1832 | }; |
| 1833 | |
| 1834 | static void init_pl08x_debugfs(struct pl08x_driver_data *pl08x) |
| 1835 | { |
| 1836 | /* Expose a simple debugfs interface to view all clocks */ |
| 1837 | (void) debugfs_create_file(dev_name(&pl08x->adev->dev), S_IFREG | S_IRUGO, |
| 1838 | NULL, pl08x, |
| 1839 | &pl08x_debugfs_operations); |
| 1840 | } |
| 1841 | |
| 1842 | #else |
| 1843 | static inline void init_pl08x_debugfs(struct pl08x_driver_data *pl08x) |
| 1844 | { |
| 1845 | } |
| 1846 | #endif |
| 1847 | |
| 1848 | static int pl08x_probe(struct amba_device *adev, struct amba_id *id) |
| 1849 | { |
| 1850 | struct pl08x_driver_data *pl08x; |
Russell King - ARM Linux | f96ca9e | 2011-01-03 22:35:08 +0000 | [diff] [blame] | 1851 | const struct vendor_data *vd = id->data; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1852 | int ret = 0; |
| 1853 | int i; |
| 1854 | |
| 1855 | ret = amba_request_regions(adev, NULL); |
| 1856 | if (ret) |
| 1857 | return ret; |
| 1858 | |
| 1859 | /* Create the driver state holder */ |
| 1860 | pl08x = kzalloc(sizeof(struct pl08x_driver_data), GFP_KERNEL); |
| 1861 | if (!pl08x) { |
| 1862 | ret = -ENOMEM; |
| 1863 | goto out_no_pl08x; |
| 1864 | } |
| 1865 | |
| 1866 | /* Initialize memcpy engine */ |
| 1867 | dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask); |
| 1868 | pl08x->memcpy.dev = &adev->dev; |
| 1869 | pl08x->memcpy.device_alloc_chan_resources = pl08x_alloc_chan_resources; |
| 1870 | pl08x->memcpy.device_free_chan_resources = pl08x_free_chan_resources; |
| 1871 | pl08x->memcpy.device_prep_dma_memcpy = pl08x_prep_dma_memcpy; |
| 1872 | pl08x->memcpy.device_prep_dma_interrupt = pl08x_prep_dma_interrupt; |
| 1873 | pl08x->memcpy.device_tx_status = pl08x_dma_tx_status; |
| 1874 | pl08x->memcpy.device_issue_pending = pl08x_issue_pending; |
| 1875 | pl08x->memcpy.device_control = pl08x_control; |
| 1876 | |
| 1877 | /* Initialize slave engine */ |
| 1878 | dma_cap_set(DMA_SLAVE, pl08x->slave.cap_mask); |
| 1879 | pl08x->slave.dev = &adev->dev; |
| 1880 | pl08x->slave.device_alloc_chan_resources = pl08x_alloc_chan_resources; |
| 1881 | pl08x->slave.device_free_chan_resources = pl08x_free_chan_resources; |
| 1882 | pl08x->slave.device_prep_dma_interrupt = pl08x_prep_dma_interrupt; |
| 1883 | pl08x->slave.device_tx_status = pl08x_dma_tx_status; |
| 1884 | pl08x->slave.device_issue_pending = pl08x_issue_pending; |
| 1885 | pl08x->slave.device_prep_slave_sg = pl08x_prep_slave_sg; |
| 1886 | pl08x->slave.device_control = pl08x_control; |
| 1887 | |
| 1888 | /* Get the platform data */ |
| 1889 | pl08x->pd = dev_get_platdata(&adev->dev); |
| 1890 | if (!pl08x->pd) { |
| 1891 | dev_err(&adev->dev, "no platform data supplied\n"); |
| 1892 | goto out_no_platdata; |
| 1893 | } |
| 1894 | |
| 1895 | /* Assign useful pointers to the driver state */ |
| 1896 | pl08x->adev = adev; |
| 1897 | pl08x->vd = vd; |
| 1898 | |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 1899 | /* By default, AHB1 only. If dualmaster, from platform */ |
| 1900 | pl08x->lli_buses = PL08X_AHB1; |
| 1901 | pl08x->mem_buses = PL08X_AHB1; |
| 1902 | if (pl08x->vd->dualmaster) { |
| 1903 | pl08x->lli_buses = pl08x->pd->lli_buses; |
| 1904 | pl08x->mem_buses = pl08x->pd->mem_buses; |
| 1905 | } |
| 1906 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1907 | /* A DMA memory pool for LLIs, align on 1-byte boundary */ |
| 1908 | pl08x->pool = dma_pool_create(DRIVER_NAME, &pl08x->adev->dev, |
| 1909 | PL08X_LLI_TSFR_SIZE, PL08X_ALIGN, 0); |
| 1910 | if (!pl08x->pool) { |
| 1911 | ret = -ENOMEM; |
| 1912 | goto out_no_lli_pool; |
| 1913 | } |
| 1914 | |
| 1915 | spin_lock_init(&pl08x->lock); |
| 1916 | |
| 1917 | pl08x->base = ioremap(adev->res.start, resource_size(&adev->res)); |
| 1918 | if (!pl08x->base) { |
| 1919 | ret = -ENOMEM; |
| 1920 | goto out_no_ioremap; |
| 1921 | } |
| 1922 | |
| 1923 | /* Turn on the PL08x */ |
| 1924 | pl08x_ensure_on(pl08x); |
| 1925 | |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1926 | /* Attach the interrupt handler */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1927 | writel(0x000000FF, pl08x->base + PL080_ERR_CLEAR); |
| 1928 | writel(0x000000FF, pl08x->base + PL080_TC_CLEAR); |
| 1929 | |
| 1930 | ret = request_irq(adev->irq[0], pl08x_irq, IRQF_DISABLED, |
Russell King - ARM Linux | b05cd8f | 2011-01-03 22:33:26 +0000 | [diff] [blame] | 1931 | DRIVER_NAME, pl08x); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1932 | if (ret) { |
| 1933 | dev_err(&adev->dev, "%s failed to request interrupt %d\n", |
| 1934 | __func__, adev->irq[0]); |
| 1935 | goto out_no_irq; |
| 1936 | } |
| 1937 | |
| 1938 | /* Initialize physical channels */ |
| 1939 | pl08x->phy_chans = kmalloc((vd->channels * sizeof(struct pl08x_phy_chan)), |
| 1940 | GFP_KERNEL); |
| 1941 | if (!pl08x->phy_chans) { |
| 1942 | dev_err(&adev->dev, "%s failed to allocate " |
| 1943 | "physical channel holders\n", |
| 1944 | __func__); |
| 1945 | goto out_no_phychans; |
| 1946 | } |
| 1947 | |
| 1948 | for (i = 0; i < vd->channels; i++) { |
| 1949 | struct pl08x_phy_chan *ch = &pl08x->phy_chans[i]; |
| 1950 | |
| 1951 | ch->id = i; |
| 1952 | ch->base = pl08x->base + PL080_Cx_BASE(i); |
| 1953 | spin_lock_init(&ch->lock); |
| 1954 | ch->serving = NULL; |
| 1955 | ch->signal = -1; |
| 1956 | dev_info(&adev->dev, |
| 1957 | "physical channel %d is %s\n", i, |
| 1958 | pl08x_phy_channel_busy(ch) ? "BUSY" : "FREE"); |
| 1959 | } |
| 1960 | |
| 1961 | /* Register as many memcpy channels as there are physical channels */ |
| 1962 | ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->memcpy, |
| 1963 | pl08x->vd->channels, false); |
| 1964 | if (ret <= 0) { |
| 1965 | dev_warn(&pl08x->adev->dev, |
| 1966 | "%s failed to enumerate memcpy channels - %d\n", |
| 1967 | __func__, ret); |
| 1968 | goto out_no_memcpy; |
| 1969 | } |
| 1970 | pl08x->memcpy.chancnt = ret; |
| 1971 | |
| 1972 | /* Register slave channels */ |
| 1973 | ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->slave, |
| 1974 | pl08x->pd->num_slave_channels, |
| 1975 | true); |
| 1976 | if (ret <= 0) { |
| 1977 | dev_warn(&pl08x->adev->dev, |
| 1978 | "%s failed to enumerate slave channels - %d\n", |
| 1979 | __func__, ret); |
| 1980 | goto out_no_slave; |
| 1981 | } |
| 1982 | pl08x->slave.chancnt = ret; |
| 1983 | |
| 1984 | ret = dma_async_device_register(&pl08x->memcpy); |
| 1985 | if (ret) { |
| 1986 | dev_warn(&pl08x->adev->dev, |
| 1987 | "%s failed to register memcpy as an async device - %d\n", |
| 1988 | __func__, ret); |
| 1989 | goto out_no_memcpy_reg; |
| 1990 | } |
| 1991 | |
| 1992 | ret = dma_async_device_register(&pl08x->slave); |
| 1993 | if (ret) { |
| 1994 | dev_warn(&pl08x->adev->dev, |
| 1995 | "%s failed to register slave as an async device - %d\n", |
| 1996 | __func__, ret); |
| 1997 | goto out_no_slave_reg; |
| 1998 | } |
| 1999 | |
| 2000 | amba_set_drvdata(adev, pl08x); |
| 2001 | init_pl08x_debugfs(pl08x); |
Russell King - ARM Linux | b05cd8f | 2011-01-03 22:33:26 +0000 | [diff] [blame] | 2002 | dev_info(&pl08x->adev->dev, "DMA: PL%03x rev%u at 0x%08llx irq %d\n", |
| 2003 | amba_part(adev), amba_rev(adev), |
| 2004 | (unsigned long long)adev->res.start, adev->irq[0]); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2005 | return 0; |
| 2006 | |
| 2007 | out_no_slave_reg: |
| 2008 | dma_async_device_unregister(&pl08x->memcpy); |
| 2009 | out_no_memcpy_reg: |
| 2010 | pl08x_free_virtual_channels(&pl08x->slave); |
| 2011 | out_no_slave: |
| 2012 | pl08x_free_virtual_channels(&pl08x->memcpy); |
| 2013 | out_no_memcpy: |
| 2014 | kfree(pl08x->phy_chans); |
| 2015 | out_no_phychans: |
| 2016 | free_irq(adev->irq[0], pl08x); |
| 2017 | out_no_irq: |
| 2018 | iounmap(pl08x->base); |
| 2019 | out_no_ioremap: |
| 2020 | dma_pool_destroy(pl08x->pool); |
| 2021 | out_no_lli_pool: |
| 2022 | out_no_platdata: |
| 2023 | kfree(pl08x); |
| 2024 | out_no_pl08x: |
| 2025 | amba_release_regions(adev); |
| 2026 | return ret; |
| 2027 | } |
| 2028 | |
| 2029 | /* PL080 has 8 channels and the PL080 have just 2 */ |
| 2030 | static struct vendor_data vendor_pl080 = { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2031 | .channels = 8, |
| 2032 | .dualmaster = true, |
| 2033 | }; |
| 2034 | |
| 2035 | static struct vendor_data vendor_pl081 = { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2036 | .channels = 2, |
| 2037 | .dualmaster = false, |
| 2038 | }; |
| 2039 | |
| 2040 | static struct amba_id pl08x_ids[] = { |
| 2041 | /* PL080 */ |
| 2042 | { |
| 2043 | .id = 0x00041080, |
| 2044 | .mask = 0x000fffff, |
| 2045 | .data = &vendor_pl080, |
| 2046 | }, |
| 2047 | /* PL081 */ |
| 2048 | { |
| 2049 | .id = 0x00041081, |
| 2050 | .mask = 0x000fffff, |
| 2051 | .data = &vendor_pl081, |
| 2052 | }, |
| 2053 | /* Nomadik 8815 PL080 variant */ |
| 2054 | { |
| 2055 | .id = 0x00280880, |
| 2056 | .mask = 0x00ffffff, |
| 2057 | .data = &vendor_pl080, |
| 2058 | }, |
| 2059 | { 0, 0 }, |
| 2060 | }; |
| 2061 | |
| 2062 | static struct amba_driver pl08x_amba_driver = { |
| 2063 | .drv.name = DRIVER_NAME, |
| 2064 | .id_table = pl08x_ids, |
| 2065 | .probe = pl08x_probe, |
| 2066 | }; |
| 2067 | |
| 2068 | static int __init pl08x_init(void) |
| 2069 | { |
| 2070 | int retval; |
| 2071 | retval = amba_driver_register(&pl08x_amba_driver); |
| 2072 | if (retval) |
| 2073 | printk(KERN_WARNING DRIVER_NAME |
Russell King - ARM Linux | e8b5e11 | 2011-01-03 22:30:24 +0000 | [diff] [blame] | 2074 | "failed to register as an AMBA device (%d)\n", |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2075 | retval); |
| 2076 | return retval; |
| 2077 | } |
| 2078 | subsys_initcall(pl08x_init); |