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