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 | * |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 18 | * The full GNU General Public License is in this distribution in the file |
| 19 | * called COPYING. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 20 | * |
| 21 | * Documentation: ARM DDI 0196G == PL080 |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 22 | * Documentation: ARM DDI 0218E == PL081 |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 23 | * Documentation: S3C6410 User's Manual == PL080S |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 24 | * |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 25 | * PL080 & PL081 both have 16 sets of DMA signals that can be routed to any |
| 26 | * channel. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 27 | * |
| 28 | * The PL080 has 8 channels available for simultaneous use, and the PL081 |
| 29 | * has only two channels. So on these DMA controllers the number of channels |
| 30 | * and the number of incoming DMA signals are two totally different things. |
| 31 | * It is usually not possible to theoretically handle all physical signals, |
| 32 | * so a multiplexing scheme with possible denial of use is necessary. |
| 33 | * |
| 34 | * The PL080 has a dual bus master, PL081 has a single master. |
| 35 | * |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 36 | * PL080S is a version modified by Samsung and used in S3C64xx SoCs. |
| 37 | * It differs in following aspects: |
| 38 | * - CH_CONFIG register at different offset, |
| 39 | * - separate CH_CONTROL2 register for transfer size, |
| 40 | * - bigger maximum transfer size, |
| 41 | * - 8-word aligned LLI, instead of 4-word, due to extra CCTL2 word, |
| 42 | * - no support for peripheral flow control. |
| 43 | * |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 44 | * Memory to peripheral transfer may be visualized as |
| 45 | * Get data from memory to DMAC |
| 46 | * Until no data left |
| 47 | * On burst request from peripheral |
| 48 | * Destination burst from DMAC to peripheral |
| 49 | * Clear burst request |
| 50 | * Raise terminal count interrupt |
| 51 | * |
| 52 | * For peripherals with a FIFO: |
| 53 | * Source burst size == half the depth of the peripheral FIFO |
| 54 | * Destination burst size == the depth of the peripheral FIFO |
| 55 | * |
| 56 | * (Bursts are irrelevant for mem to mem transfers - there are no burst |
| 57 | * signals, the DMA controller will simply facilitate its AHB master.) |
| 58 | * |
| 59 | * ASSUMES default (little) endianness for DMA transfers |
| 60 | * |
Russell King - ARM Linux | 9dc2c20 | 2011-01-03 22:33:06 +0000 | [diff] [blame] | 61 | * The PL08x has two flow control settings: |
| 62 | * - DMAC flow control: the transfer size defines the number of transfers |
| 63 | * which occur for the current LLI entry, and the DMAC raises TC at the |
| 64 | * end of every LLI entry. Observed behaviour shows the DMAC listening |
| 65 | * to both the BREQ and SREQ signals (contrary to documented), |
| 66 | * transferring data if either is active. The LBREQ and LSREQ signals |
| 67 | * are ignored. |
| 68 | * |
| 69 | * - Peripheral flow control: the transfer size is ignored (and should be |
| 70 | * zero). The data is transferred from the current LLI entry, until |
| 71 | * after the final transfer signalled by LBREQ or LSREQ. The DMAC |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 72 | * will then move to the next LLI entry. Unsupported by PL080S. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 73 | */ |
Russell King - ARM Linux | 730404a | 2011-01-03 22:34:07 +0000 | [diff] [blame] | 74 | #include <linux/amba/bus.h> |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 75 | #include <linux/amba/pl08x.h> |
| 76 | #include <linux/debugfs.h> |
Viresh Kumar | 0c38d70 | 2011-08-05 15:32:28 +0530 | [diff] [blame] | 77 | #include <linux/delay.h> |
| 78 | #include <linux/device.h> |
| 79 | #include <linux/dmaengine.h> |
| 80 | #include <linux/dmapool.h> |
Vinod Koul | 8516f52 | 2011-09-02 16:43:44 +0530 | [diff] [blame] | 81 | #include <linux/dma-mapping.h> |
Sachin Kamat | 6d05c9f | 2014-01-23 16:10:07 +0530 | [diff] [blame] | 82 | #include <linux/export.h> |
Viresh Kumar | 0c38d70 | 2011-08-05 15:32:28 +0530 | [diff] [blame] | 83 | #include <linux/init.h> |
| 84 | #include <linux/interrupt.h> |
| 85 | #include <linux/module.h> |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 86 | #include <linux/of.h> |
| 87 | #include <linux/of_dma.h> |
Viresh Kumar | b7b6018 | 2011-08-05 15:32:33 +0530 | [diff] [blame] | 88 | #include <linux/pm_runtime.h> |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 89 | #include <linux/seq_file.h> |
Viresh Kumar | 0c38d70 | 2011-08-05 15:32:28 +0530 | [diff] [blame] | 90 | #include <linux/slab.h> |
Alessandro Rubini | 3a95b9f | 2012-11-24 00:22:56 +0000 | [diff] [blame] | 91 | #include <linux/amba/pl080.h> |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 92 | |
Russell King - ARM Linux | d2ebfb3 | 2012-03-06 22:34:26 +0000 | [diff] [blame] | 93 | #include "dmaengine.h" |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 94 | #include "virt-dma.h" |
Russell King - ARM Linux | d2ebfb3 | 2012-03-06 22:34:26 +0000 | [diff] [blame] | 95 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 96 | #define DRIVER_NAME "pl08xdmac" |
| 97 | |
Mark Brown | ea524c7 | 2015-03-17 23:25:36 +0000 | [diff] [blame] | 98 | #define PL80X_DMA_BUSWIDTHS \ |
| 99 | BIT(DMA_SLAVE_BUSWIDTH_UNDEFINED) | \ |
| 100 | BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \ |
| 101 | BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \ |
| 102 | BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) |
| 103 | |
Russell King - ARM Linux | 7703eac | 2011-08-31 09:34:35 +0100 | [diff] [blame] | 104 | static struct amba_driver pl08x_amba_driver; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 105 | struct pl08x_driver_data; |
Russell King - ARM Linux | 7703eac | 2011-08-31 09:34:35 +0100 | [diff] [blame] | 106 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 107 | /** |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 108 | * struct vendor_data - vendor-specific config parameters for PL08x derivatives |
Linus Walleij | da7cbd2 | 2017-04-02 16:50:44 +0200 | [diff] [blame] | 109 | * @config_offset: offset to the configuration register |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 110 | * @channels: the number of channels available in this variant |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 111 | * @signals: the number of request signals available from the hardware |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 112 | * @dualmaster: whether this version supports dual AHB masters or not. |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 113 | * @nomadik: whether the channels have Nomadik security extension bits |
| 114 | * that need to be checked for permission before use and some registers are |
| 115 | * missing |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 116 | * @pl080s: whether this version is a PL080S, which has separate register and |
| 117 | * LLI word for transfer size. |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 118 | * @max_transfer_size: the maximum single element transfer size for this |
| 119 | * PL08x variant. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 120 | */ |
| 121 | struct vendor_data { |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 122 | u8 config_offset; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 123 | u8 channels; |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 124 | u8 signals; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 125 | bool dualmaster; |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 126 | bool nomadik; |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 127 | bool pl080s; |
Tomasz Figa | 5110e51 | 2013-08-11 19:59:18 +0200 | [diff] [blame] | 128 | u32 max_transfer_size; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | /** |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 132 | * struct pl08x_bus_data - information of source or destination |
| 133 | * busses for a transfer |
| 134 | * @addr: current address |
| 135 | * @maxwidth: the maximum width of a transfer on this bus |
| 136 | * @buswidth: the width of this bus in bytes: 1, 2 or 4 |
| 137 | */ |
| 138 | struct pl08x_bus_data { |
| 139 | dma_addr_t addr; |
| 140 | u8 maxwidth; |
| 141 | u8 buswidth; |
| 142 | }; |
| 143 | |
Andre Przywara | 1c38b28 | 2013-08-19 12:19:28 +0200 | [diff] [blame] | 144 | #define IS_BUS_ALIGNED(bus) IS_ALIGNED((bus)->addr, (bus)->buswidth) |
| 145 | |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 146 | /** |
| 147 | * struct pl08x_phy_chan - holder for the physical channels |
| 148 | * @id: physical index to this channel |
Linus Walleij | da7cbd2 | 2017-04-02 16:50:44 +0200 | [diff] [blame] | 149 | * @base: memory base address for this physical channel |
| 150 | * @reg_config: configuration address for this physical channel |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 151 | * @lock: a lock to use when altering an instance of this struct |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 152 | * @serving: the virtual channel currently being served by this physical |
| 153 | * channel |
Russell King | ad0de2a | 2012-05-25 11:15:15 +0100 | [diff] [blame] | 154 | * @locked: channel unavailable for the system, e.g. dedicated to secure |
| 155 | * world |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 156 | */ |
| 157 | struct pl08x_phy_chan { |
| 158 | unsigned int id; |
| 159 | void __iomem *base; |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 160 | void __iomem *reg_config; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 161 | spinlock_t lock; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 162 | struct pl08x_dma_chan *serving; |
Russell King | ad0de2a | 2012-05-25 11:15:15 +0100 | [diff] [blame] | 163 | bool locked; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | /** |
| 167 | * struct pl08x_sg - structure containing data per sg |
| 168 | * @src_addr: src address of sg |
| 169 | * @dst_addr: dst address of sg |
| 170 | * @len: transfer len in bytes |
| 171 | * @node: node for txd's dsg_list |
| 172 | */ |
| 173 | struct pl08x_sg { |
| 174 | dma_addr_t src_addr; |
| 175 | dma_addr_t dst_addr; |
| 176 | size_t len; |
| 177 | struct list_head node; |
| 178 | }; |
| 179 | |
| 180 | /** |
| 181 | * struct pl08x_txd - wrapper for struct dma_async_tx_descriptor |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 182 | * @vd: virtual DMA descriptor |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 183 | * @dsg_list: list of children sg's |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 184 | * @llis_bus: DMA memory address (physical) start for the LLIs |
| 185 | * @llis_va: virtual memory address start for the LLIs |
| 186 | * @cctl: control reg values for current txd |
| 187 | * @ccfg: config reg values for current txd |
Russell King | 1853613 | 2012-05-26 14:42:23 +0100 | [diff] [blame] | 188 | * @done: this marks completed descriptors, which should not have their |
| 189 | * mux released. |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 190 | * @cyclic: indicate cyclic transfers |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 191 | */ |
| 192 | struct pl08x_txd { |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 193 | struct virt_dma_desc vd; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 194 | struct list_head dsg_list; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 195 | dma_addr_t llis_bus; |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 196 | u32 *llis_va; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 197 | /* Default cctl value for LLIs */ |
| 198 | u32 cctl; |
| 199 | /* |
| 200 | * Settings to be put into the physical channel when we |
| 201 | * trigger this txd. Other registers are in llis_va[0]. |
| 202 | */ |
| 203 | u32 ccfg; |
Russell King | 1853613 | 2012-05-26 14:42:23 +0100 | [diff] [blame] | 204 | bool done; |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 205 | bool cyclic; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | /** |
Vinod Koul | 8ee1bdc | 2017-04-03 09:02:36 +0530 | [diff] [blame] | 209 | * enum pl08x_dma_chan_state - holds the PL08x specific virtual channel |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 210 | * states |
| 211 | * @PL08X_CHAN_IDLE: the channel is idle |
| 212 | * @PL08X_CHAN_RUNNING: the channel has allocated a physical transport |
| 213 | * channel and is running a transfer on it |
| 214 | * @PL08X_CHAN_PAUSED: the channel has allocated a physical transport |
| 215 | * channel, but the transfer is currently paused |
| 216 | * @PL08X_CHAN_WAITING: the channel is waiting for a physical transport |
| 217 | * channel to become available (only pertains to memcpy channels) |
| 218 | */ |
| 219 | enum pl08x_dma_chan_state { |
| 220 | PL08X_CHAN_IDLE, |
| 221 | PL08X_CHAN_RUNNING, |
| 222 | PL08X_CHAN_PAUSED, |
| 223 | PL08X_CHAN_WAITING, |
| 224 | }; |
| 225 | |
| 226 | /** |
| 227 | * struct pl08x_dma_chan - this structure wraps a DMA ENGINE channel |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 228 | * @vc: wrappped virtual channel |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 229 | * @phychan: the physical channel utilized by this channel, if there is one |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 230 | * @name: name of channel |
| 231 | * @cd: channel platform data |
Linus Walleij | da7cbd2 | 2017-04-02 16:50:44 +0200 | [diff] [blame] | 232 | * @cfg: slave configuration |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 233 | * @at: active transaction on this channel |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 234 | * @host: a pointer to the host (internal use) |
| 235 | * @state: whether the channel is idle, paused, running etc |
| 236 | * @slave: whether this channel is a device (slave) or for memcpy |
Russell King | ad0de2a | 2012-05-25 11:15:15 +0100 | [diff] [blame] | 237 | * @signal: the physical DMA request signal which this channel is using |
Russell King | 5e2479b | 2012-05-25 11:32:45 +0100 | [diff] [blame] | 238 | * @mux_use: count of descriptors using this DMA request signal setting |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 239 | */ |
| 240 | struct pl08x_dma_chan { |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 241 | struct virt_dma_chan vc; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 242 | struct pl08x_phy_chan *phychan; |
Russell King | 550ec36 | 2012-05-28 10:18:55 +0100 | [diff] [blame] | 243 | const char *name; |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 244 | struct pl08x_channel_data *cd; |
Russell King | ed91c13 | 2012-05-16 11:02:40 +0100 | [diff] [blame] | 245 | struct dma_slave_config cfg; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 246 | struct pl08x_txd *at; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 247 | struct pl08x_driver_data *host; |
| 248 | enum pl08x_dma_chan_state state; |
| 249 | bool slave; |
Russell King | ad0de2a | 2012-05-25 11:15:15 +0100 | [diff] [blame] | 250 | int signal; |
Russell King | 5e2479b | 2012-05-25 11:32:45 +0100 | [diff] [blame] | 251 | unsigned mux_use; |
Russell King | b23f204 | 2012-05-16 10:48:44 +0100 | [diff] [blame] | 252 | }; |
| 253 | |
| 254 | /** |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 255 | * struct pl08x_driver_data - the local state holder for the PL08x |
| 256 | * @slave: slave engine for this instance |
| 257 | * @memcpy: memcpy engine for this instance |
| 258 | * @base: virtual memory base (remapped) for the PL08x |
| 259 | * @adev: the corresponding AMBA (PrimeCell) bus entry |
| 260 | * @vd: vendor data for this PL08x variant |
| 261 | * @pd: platform data passed in from the platform/machine |
| 262 | * @phy_chans: array of data for the physical channels |
| 263 | * @pool: a pool for the LLI descriptors |
Viresh Kumar | 3e27ee8 | 2011-08-05 15:32:27 +0530 | [diff] [blame] | 264 | * @lli_buses: bitmask to or in to LLI pointer selecting AHB port for LLI |
| 265 | * fetches |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 266 | * @mem_buses: set to indicate memory transfers on AHB2. |
Linus Walleij | da7cbd2 | 2017-04-02 16:50:44 +0200 | [diff] [blame] | 267 | * @lli_words: how many words are used in each LLI item for this variant |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 268 | */ |
| 269 | struct pl08x_driver_data { |
| 270 | struct dma_device slave; |
| 271 | struct dma_device memcpy; |
| 272 | void __iomem *base; |
| 273 | struct amba_device *adev; |
Russell King - ARM Linux | f96ca9ec | 2011-01-03 22:35:08 +0000 | [diff] [blame] | 274 | const struct vendor_data *vd; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 275 | struct pl08x_platform_data *pd; |
| 276 | struct pl08x_phy_chan *phy_chans; |
| 277 | struct dma_pool *pool; |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 278 | u8 lli_buses; |
| 279 | u8 mem_buses; |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 280 | u8 lli_words; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | /* |
| 284 | * PL08X specific defines |
| 285 | */ |
| 286 | |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 287 | /* The order of words in an LLI. */ |
| 288 | #define PL080_LLI_SRC 0 |
| 289 | #define PL080_LLI_DST 1 |
| 290 | #define PL080_LLI_LLI 2 |
| 291 | #define PL080_LLI_CCTL 3 |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 292 | #define PL080S_LLI_CCTL2 4 |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 293 | |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 294 | /* Total words in an LLI. */ |
| 295 | #define PL080_LLI_WORDS 4 |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 296 | #define PL080S_LLI_WORDS 8 |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 297 | |
| 298 | /* |
| 299 | * Number of LLIs in each LLI buffer allocated for one transfer |
| 300 | * (maximum times we call dma_pool_alloc on this pool without freeing) |
| 301 | */ |
| 302 | #define MAX_NUM_TSFR_LLIS 512 |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 303 | #define PL08X_ALIGN 8 |
| 304 | |
| 305 | static inline struct pl08x_dma_chan *to_pl08x_chan(struct dma_chan *chan) |
| 306 | { |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 307 | return container_of(chan, struct pl08x_dma_chan, vc.chan); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Russell King - ARM Linux | 501e67e | 2011-01-03 22:44:57 +0000 | [diff] [blame] | 310 | static inline struct pl08x_txd *to_pl08x_txd(struct dma_async_tx_descriptor *tx) |
| 311 | { |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 312 | return container_of(tx, struct pl08x_txd, vd.tx); |
Russell King - ARM Linux | 501e67e | 2011-01-03 22:44:57 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 315 | /* |
Russell King | 6b16c8b | 2012-05-25 11:10:58 +0100 | [diff] [blame] | 316 | * Mux handling. |
| 317 | * |
| 318 | * This gives us the DMA request input to the PL08x primecell which the |
| 319 | * peripheral described by the channel data will be routed to, possibly |
| 320 | * via a board/SoC specific external MUX. One important point to note |
| 321 | * here is that this does not depend on the physical channel. |
| 322 | */ |
Russell King | ad0de2a | 2012-05-25 11:15:15 +0100 | [diff] [blame] | 323 | static int pl08x_request_mux(struct pl08x_dma_chan *plchan) |
Russell King | 6b16c8b | 2012-05-25 11:10:58 +0100 | [diff] [blame] | 324 | { |
| 325 | const struct pl08x_platform_data *pd = plchan->host->pd; |
| 326 | int ret; |
| 327 | |
Mark Brown | d7cabee | 2013-06-19 20:38:28 +0100 | [diff] [blame] | 328 | if (plchan->mux_use++ == 0 && pd->get_xfer_signal) { |
| 329 | ret = pd->get_xfer_signal(plchan->cd); |
Russell King | 5e2479b | 2012-05-25 11:32:45 +0100 | [diff] [blame] | 330 | if (ret < 0) { |
| 331 | plchan->mux_use = 0; |
Russell King | 6b16c8b | 2012-05-25 11:10:58 +0100 | [diff] [blame] | 332 | return ret; |
Russell King | 5e2479b | 2012-05-25 11:32:45 +0100 | [diff] [blame] | 333 | } |
Russell King | 6b16c8b | 2012-05-25 11:10:58 +0100 | [diff] [blame] | 334 | |
Russell King | ad0de2a | 2012-05-25 11:15:15 +0100 | [diff] [blame] | 335 | plchan->signal = ret; |
Russell King | 6b16c8b | 2012-05-25 11:10:58 +0100 | [diff] [blame] | 336 | } |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static void pl08x_release_mux(struct pl08x_dma_chan *plchan) |
| 341 | { |
| 342 | const struct pl08x_platform_data *pd = plchan->host->pd; |
| 343 | |
Russell King | 5e2479b | 2012-05-25 11:32:45 +0100 | [diff] [blame] | 344 | if (plchan->signal >= 0) { |
| 345 | WARN_ON(plchan->mux_use == 0); |
| 346 | |
Mark Brown | d7cabee | 2013-06-19 20:38:28 +0100 | [diff] [blame] | 347 | if (--plchan->mux_use == 0 && pd->put_xfer_signal) { |
| 348 | pd->put_xfer_signal(plchan->cd, plchan->signal); |
Russell King | 5e2479b | 2012-05-25 11:32:45 +0100 | [diff] [blame] | 349 | plchan->signal = -1; |
| 350 | } |
Russell King | 6b16c8b | 2012-05-25 11:10:58 +0100 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
| 354 | /* |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 355 | * Physical channel handling |
| 356 | */ |
| 357 | |
| 358 | /* Whether a certain channel is busy or not */ |
| 359 | static int pl08x_phy_channel_busy(struct pl08x_phy_chan *ch) |
| 360 | { |
| 361 | unsigned int val; |
| 362 | |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 363 | val = readl(ch->reg_config); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 364 | return val & PL080_CONFIG_ACTIVE; |
| 365 | } |
| 366 | |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 367 | static void pl08x_write_lli(struct pl08x_driver_data *pl08x, |
| 368 | struct pl08x_phy_chan *phychan, const u32 *lli, u32 ccfg) |
| 369 | { |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 370 | if (pl08x->vd->pl080s) |
| 371 | dev_vdbg(&pl08x->adev->dev, |
| 372 | "WRITE channel %d: csrc=0x%08x, cdst=0x%08x, " |
| 373 | "clli=0x%08x, cctl=0x%08x, cctl2=0x%08x, ccfg=0x%08x\n", |
| 374 | phychan->id, lli[PL080_LLI_SRC], lli[PL080_LLI_DST], |
| 375 | lli[PL080_LLI_LLI], lli[PL080_LLI_CCTL], |
| 376 | lli[PL080S_LLI_CCTL2], ccfg); |
| 377 | else |
| 378 | dev_vdbg(&pl08x->adev->dev, |
| 379 | "WRITE channel %d: csrc=0x%08x, cdst=0x%08x, " |
| 380 | "clli=0x%08x, cctl=0x%08x, ccfg=0x%08x\n", |
| 381 | phychan->id, lli[PL080_LLI_SRC], lli[PL080_LLI_DST], |
| 382 | lli[PL080_LLI_LLI], lli[PL080_LLI_CCTL], ccfg); |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 383 | |
| 384 | writel_relaxed(lli[PL080_LLI_SRC], phychan->base + PL080_CH_SRC_ADDR); |
| 385 | writel_relaxed(lli[PL080_LLI_DST], phychan->base + PL080_CH_DST_ADDR); |
| 386 | writel_relaxed(lli[PL080_LLI_LLI], phychan->base + PL080_CH_LLI); |
| 387 | writel_relaxed(lli[PL080_LLI_CCTL], phychan->base + PL080_CH_CONTROL); |
| 388 | |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 389 | if (pl08x->vd->pl080s) |
| 390 | writel_relaxed(lli[PL080S_LLI_CCTL2], |
| 391 | phychan->base + PL080S_CH_CONTROL2); |
| 392 | |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 393 | writel(ccfg, phychan->reg_config); |
| 394 | } |
| 395 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 396 | /* |
| 397 | * 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] | 398 | * The next LLI pointer and the configuration interrupt bit have |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 399 | * been set when the LLIs were constructed. Poke them into the hardware |
| 400 | * and start the transfer. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 401 | */ |
Russell King | eab8253 | 2012-05-25 12:32:00 +0100 | [diff] [blame] | 402 | static void pl08x_start_next_txd(struct pl08x_dma_chan *plchan) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 403 | { |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 404 | struct pl08x_driver_data *pl08x = plchan->host; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 405 | struct pl08x_phy_chan *phychan = plchan->phychan; |
Russell King | 879f127 | 2012-05-26 14:27:40 +0100 | [diff] [blame] | 406 | struct virt_dma_desc *vd = vchan_next_desc(&plchan->vc); |
| 407 | struct pl08x_txd *txd = to_pl08x_txd(&vd->tx); |
Russell King - ARM Linux | 09b3c32 | 2011-01-03 22:39:53 +0000 | [diff] [blame] | 408 | u32 val; |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 409 | |
Russell King | 879f127 | 2012-05-26 14:27:40 +0100 | [diff] [blame] | 410 | list_del(&txd->vd.node); |
Russell King | eab8253 | 2012-05-25 12:32:00 +0100 | [diff] [blame] | 411 | |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 412 | plchan->at = txd; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 413 | |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 414 | /* Wait for channel inactive */ |
| 415 | while (pl08x_phy_channel_busy(phychan)) |
Russell King - ARM Linux | 19386b32 | 2011-01-03 22:36:29 +0000 | [diff] [blame] | 416 | cpu_relax(); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 417 | |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 418 | pl08x_write_lli(pl08x, phychan, &txd->llis_va[0], txd->ccfg); |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 419 | |
| 420 | /* Enable the DMA channel */ |
| 421 | /* Do not access config register until channel shows as disabled */ |
Linus Walleij | ded091f | 2017-04-02 16:50:53 +0200 | [diff] [blame] | 422 | while (readl(pl08x->base + PL080_EN_CHAN) & BIT(phychan->id)) |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 423 | cpu_relax(); |
| 424 | |
| 425 | /* Do not access config register until channel shows as inactive */ |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 426 | val = readl(phychan->reg_config); |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 427 | while ((val & PL080_CONFIG_ACTIVE) || (val & PL080_CONFIG_ENABLE)) |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 428 | val = readl(phychan->reg_config); |
Russell King - ARM Linux | c885bee | 2011-01-03 22:38:52 +0000 | [diff] [blame] | 429 | |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 430 | writel(val | PL080_CONFIG_ENABLE, phychan->reg_config); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* |
Russell King - ARM Linux | 8179661 | 2011-01-27 12:37:44 +0000 | [diff] [blame] | 434 | * Pause the channel by setting the HALT bit. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 435 | * |
Russell King - ARM Linux | 8179661 | 2011-01-27 12:37:44 +0000 | [diff] [blame] | 436 | * For M->P transfers, pause the DMAC first and then stop the peripheral - |
| 437 | * the FIFO can only drain if the peripheral is still requesting data. |
| 438 | * (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] | 439 | * |
Russell King - ARM Linux | 8179661 | 2011-01-27 12:37:44 +0000 | [diff] [blame] | 440 | * For P->M transfers, disable the peripheral first to stop it filling |
| 441 | * the DMAC FIFO, and then pause the DMAC. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 442 | */ |
| 443 | static void pl08x_pause_phy_chan(struct pl08x_phy_chan *ch) |
| 444 | { |
| 445 | u32 val; |
Russell King - ARM Linux | 8179661 | 2011-01-27 12:37:44 +0000 | [diff] [blame] | 446 | int timeout; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 447 | |
| 448 | /* Set the HALT bit and wait for the FIFO to drain */ |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 449 | val = readl(ch->reg_config); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 450 | val |= PL080_CONFIG_HALT; |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 451 | writel(val, ch->reg_config); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 452 | |
| 453 | /* Wait for channel inactive */ |
Russell King - ARM Linux | 8179661 | 2011-01-27 12:37:44 +0000 | [diff] [blame] | 454 | for (timeout = 1000; timeout; timeout--) { |
| 455 | if (!pl08x_phy_channel_busy(ch)) |
| 456 | break; |
| 457 | udelay(1); |
| 458 | } |
| 459 | if (pl08x_phy_channel_busy(ch)) |
| 460 | pr_err("pl08x: channel%u timeout waiting for pause\n", ch->id); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | static void pl08x_resume_phy_chan(struct pl08x_phy_chan *ch) |
| 464 | { |
| 465 | u32 val; |
| 466 | |
| 467 | /* Clear the HALT bit */ |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 468 | val = readl(ch->reg_config); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 469 | val &= ~PL080_CONFIG_HALT; |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 470 | writel(val, ch->reg_config); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 471 | } |
| 472 | |
Russell King - ARM Linux | fb52621 | 2011-01-27 12:32:53 +0000 | [diff] [blame] | 473 | /* |
| 474 | * pl08x_terminate_phy_chan() stops the channel, clears the FIFO and |
| 475 | * clears any pending interrupt status. This should not be used for |
| 476 | * an on-going transfer, but as a method of shutting down a channel |
| 477 | * (eg, when it's no longer used) or terminating a transfer. |
| 478 | */ |
| 479 | static void pl08x_terminate_phy_chan(struct pl08x_driver_data *pl08x, |
| 480 | struct pl08x_phy_chan *ch) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 481 | { |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 482 | u32 val = readl(ch->reg_config); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 483 | |
Russell King - ARM Linux | fb52621 | 2011-01-27 12:32:53 +0000 | [diff] [blame] | 484 | val &= ~(PL080_CONFIG_ENABLE | PL080_CONFIG_ERR_IRQ_MASK | |
Leonardo Carreras | 5835aa8 | 2015-05-05 19:40:52 -0400 | [diff] [blame] | 485 | PL080_CONFIG_TC_IRQ_MASK); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 486 | |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 487 | writel(val, ch->reg_config); |
Russell King - ARM Linux | fb52621 | 2011-01-27 12:32:53 +0000 | [diff] [blame] | 488 | |
Linus Walleij | ded091f | 2017-04-02 16:50:53 +0200 | [diff] [blame] | 489 | writel(BIT(ch->id), pl08x->base + PL080_ERR_CLEAR); |
| 490 | writel(BIT(ch->id), pl08x->base + PL080_TC_CLEAR); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static inline u32 get_bytes_in_cctl(u32 cctl) |
| 494 | { |
| 495 | /* The source width defines the number of bytes */ |
| 496 | u32 bytes = cctl & PL080_CONTROL_TRANSFER_SIZE_MASK; |
| 497 | |
Alban Bedel | f3287a5 | 2013-08-11 19:59:19 +0200 | [diff] [blame] | 498 | cctl &= PL080_CONTROL_SWIDTH_MASK; |
| 499 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 500 | switch (cctl >> PL080_CONTROL_SWIDTH_SHIFT) { |
| 501 | case PL080_WIDTH_8BIT: |
| 502 | break; |
| 503 | case PL080_WIDTH_16BIT: |
| 504 | bytes *= 2; |
| 505 | break; |
| 506 | case PL080_WIDTH_32BIT: |
| 507 | bytes *= 4; |
| 508 | break; |
| 509 | } |
| 510 | return bytes; |
| 511 | } |
| 512 | |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 513 | static inline u32 get_bytes_in_cctl_pl080s(u32 cctl, u32 cctl1) |
| 514 | { |
| 515 | /* The source width defines the number of bytes */ |
| 516 | u32 bytes = cctl1 & PL080S_CONTROL_TRANSFER_SIZE_MASK; |
| 517 | |
Alban Bedel | f3287a5 | 2013-08-11 19:59:19 +0200 | [diff] [blame] | 518 | cctl &= PL080_CONTROL_SWIDTH_MASK; |
| 519 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 520 | switch (cctl >> PL080_CONTROL_SWIDTH_SHIFT) { |
| 521 | case PL080_WIDTH_8BIT: |
| 522 | break; |
| 523 | case PL080_WIDTH_16BIT: |
| 524 | bytes *= 2; |
| 525 | break; |
| 526 | case PL080_WIDTH_32BIT: |
| 527 | bytes *= 4; |
| 528 | break; |
| 529 | } |
| 530 | return bytes; |
| 531 | } |
| 532 | |
| 533 | /* The channel should be paused when calling this */ |
| 534 | static u32 pl08x_getbytes_chan(struct pl08x_dma_chan *plchan) |
| 535 | { |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 536 | struct pl08x_driver_data *pl08x = plchan->host; |
| 537 | const u32 *llis_va, *llis_va_limit; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 538 | struct pl08x_phy_chan *ch; |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 539 | dma_addr_t llis_bus; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 540 | struct pl08x_txd *txd; |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 541 | u32 llis_max_words; |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 542 | size_t bytes; |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 543 | u32 clli; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 544 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 545 | ch = plchan->phychan; |
| 546 | txd = plchan->at; |
| 547 | |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 548 | if (!ch || !txd) |
| 549 | return 0; |
| 550 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 551 | /* |
Russell King - ARM Linux | db9f136 | 2011-01-03 22:38:32 +0000 | [diff] [blame] | 552 | * Follow the LLIs to get the number of remaining |
| 553 | * bytes in the currently active transaction. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 554 | */ |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 555 | clli = readl(ch->base + PL080_CH_LLI) & ~PL080_LLI_LM_AHB2; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 556 | |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 557 | /* First get the remaining bytes in the active transfer */ |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 558 | if (pl08x->vd->pl080s) |
| 559 | bytes = get_bytes_in_cctl_pl080s( |
| 560 | readl(ch->base + PL080_CH_CONTROL), |
| 561 | readl(ch->base + PL080S_CH_CONTROL2)); |
| 562 | else |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 563 | bytes = get_bytes_in_cctl(readl(ch->base + PL080_CH_CONTROL)); |
| 564 | |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 565 | if (!clli) |
| 566 | return bytes; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 567 | |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 568 | llis_va = txd->llis_va; |
| 569 | llis_bus = txd->llis_bus; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 570 | |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 571 | llis_max_words = pl08x->lli_words * MAX_NUM_TSFR_LLIS; |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 572 | BUG_ON(clli < llis_bus || clli >= llis_bus + |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 573 | sizeof(u32) * llis_max_words); |
Russell King - ARM Linux | db9f136 | 2011-01-03 22:38:32 +0000 | [diff] [blame] | 574 | |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 575 | /* |
| 576 | * Locate the next LLI - as this is an array, |
| 577 | * it's simple maths to find. |
| 578 | */ |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 579 | llis_va += (clli - llis_bus) / sizeof(u32); |
Russell King - ARM Linux | db9f136 | 2011-01-03 22:38:32 +0000 | [diff] [blame] | 580 | |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 581 | llis_va_limit = llis_va + llis_max_words; |
| 582 | |
| 583 | for (; llis_va < llis_va_limit; llis_va += pl08x->lli_words) { |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 584 | if (pl08x->vd->pl080s) |
| 585 | bytes += get_bytes_in_cctl_pl080s( |
| 586 | llis_va[PL080_LLI_CCTL], |
| 587 | llis_va[PL080S_LLI_CCTL2]); |
| 588 | else |
| 589 | bytes += get_bytes_in_cctl(llis_va[PL080_LLI_CCTL]); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 590 | |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 591 | /* |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 592 | * A LLI pointer going backward terminates the LLI list |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 593 | */ |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 594 | if (llis_va[PL080_LLI_LLI] <= clli) |
Tomasz Figa | 68a7faa | 2013-08-11 19:59:13 +0200 | [diff] [blame] | 595 | break; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 598 | return bytes; |
| 599 | } |
| 600 | |
| 601 | /* |
| 602 | * Allocate a physical channel for a virtual channel |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 603 | * |
| 604 | * Try to locate a physical channel to be used for this transfer. If all |
| 605 | * are taken return NULL and the requester will have to cope by using |
| 606 | * some fallback PIO mode or retrying later. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 607 | */ |
| 608 | static struct pl08x_phy_chan * |
| 609 | pl08x_get_phy_channel(struct pl08x_driver_data *pl08x, |
| 610 | struct pl08x_dma_chan *virt_chan) |
| 611 | { |
| 612 | struct pl08x_phy_chan *ch = NULL; |
| 613 | unsigned long flags; |
| 614 | int i; |
| 615 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 616 | for (i = 0; i < pl08x->vd->channels; i++) { |
| 617 | ch = &pl08x->phy_chans[i]; |
| 618 | |
| 619 | spin_lock_irqsave(&ch->lock, flags); |
| 620 | |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 621 | if (!ch->locked && !ch->serving) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 622 | ch->serving = virt_chan; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 623 | spin_unlock_irqrestore(&ch->lock, flags); |
| 624 | break; |
| 625 | } |
| 626 | |
| 627 | spin_unlock_irqrestore(&ch->lock, flags); |
| 628 | } |
| 629 | |
| 630 | if (i == pl08x->vd->channels) { |
| 631 | /* No physical channel available, cope with it */ |
| 632 | return NULL; |
| 633 | } |
| 634 | |
| 635 | return ch; |
| 636 | } |
| 637 | |
Russell King | a5a488d | 2012-05-26 13:54:15 +0100 | [diff] [blame] | 638 | /* Mark the physical channel as free. Note, this write is atomic. */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 639 | static inline void pl08x_put_phy_channel(struct pl08x_driver_data *pl08x, |
| 640 | struct pl08x_phy_chan *ch) |
| 641 | { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 642 | ch->serving = NULL; |
Russell King | a5a488d | 2012-05-26 13:54:15 +0100 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /* |
| 646 | * Try to allocate a physical channel. When successful, assign it to |
| 647 | * this virtual channel, and initiate the next descriptor. The |
| 648 | * virtual channel lock must be held at this point. |
| 649 | */ |
| 650 | static void pl08x_phy_alloc_and_start(struct pl08x_dma_chan *plchan) |
| 651 | { |
| 652 | struct pl08x_driver_data *pl08x = plchan->host; |
| 653 | struct pl08x_phy_chan *ch; |
| 654 | |
| 655 | ch = pl08x_get_phy_channel(pl08x, plchan); |
| 656 | if (!ch) { |
| 657 | dev_dbg(&pl08x->adev->dev, "no physical channel available for xfer on %s\n", plchan->name); |
| 658 | plchan->state = PL08X_CHAN_WAITING; |
| 659 | return; |
| 660 | } |
| 661 | |
| 662 | dev_dbg(&pl08x->adev->dev, "allocated physical channel %d for xfer on %s\n", |
| 663 | ch->id, plchan->name); |
| 664 | |
| 665 | plchan->phychan = ch; |
| 666 | plchan->state = PL08X_CHAN_RUNNING; |
| 667 | pl08x_start_next_txd(plchan); |
| 668 | } |
| 669 | |
| 670 | static void pl08x_phy_reassign_start(struct pl08x_phy_chan *ch, |
| 671 | struct pl08x_dma_chan *plchan) |
| 672 | { |
| 673 | struct pl08x_driver_data *pl08x = plchan->host; |
| 674 | |
| 675 | dev_dbg(&pl08x->adev->dev, "reassigned physical channel %d for xfer on %s\n", |
| 676 | ch->id, plchan->name); |
| 677 | |
| 678 | /* |
| 679 | * We do this without taking the lock; we're really only concerned |
| 680 | * about whether this pointer is NULL or not, and we're guaranteed |
| 681 | * that this will only be called when it _already_ is non-NULL. |
| 682 | */ |
| 683 | ch->serving = plchan; |
| 684 | plchan->phychan = ch; |
| 685 | plchan->state = PL08X_CHAN_RUNNING; |
| 686 | pl08x_start_next_txd(plchan); |
| 687 | } |
| 688 | |
| 689 | /* |
| 690 | * Free a physical DMA channel, potentially reallocating it to another |
| 691 | * virtual channel if we have any pending. |
| 692 | */ |
| 693 | static void pl08x_phy_free(struct pl08x_dma_chan *plchan) |
| 694 | { |
| 695 | struct pl08x_driver_data *pl08x = plchan->host; |
| 696 | struct pl08x_dma_chan *p, *next; |
| 697 | |
| 698 | retry: |
| 699 | next = NULL; |
| 700 | |
| 701 | /* Find a waiting virtual channel for the next transfer. */ |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 702 | list_for_each_entry(p, &pl08x->memcpy.channels, vc.chan.device_node) |
Russell King | a5a488d | 2012-05-26 13:54:15 +0100 | [diff] [blame] | 703 | if (p->state == PL08X_CHAN_WAITING) { |
| 704 | next = p; |
| 705 | break; |
| 706 | } |
| 707 | |
| 708 | if (!next) { |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 709 | list_for_each_entry(p, &pl08x->slave.channels, vc.chan.device_node) |
Russell King | a5a488d | 2012-05-26 13:54:15 +0100 | [diff] [blame] | 710 | if (p->state == PL08X_CHAN_WAITING) { |
| 711 | next = p; |
| 712 | break; |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | /* Ensure that the physical channel is stopped */ |
| 717 | pl08x_terminate_phy_chan(pl08x, plchan->phychan); |
| 718 | |
| 719 | if (next) { |
| 720 | bool success; |
| 721 | |
| 722 | /* |
| 723 | * Eww. We know this isn't going to deadlock |
| 724 | * but lockdep probably doesn't. |
| 725 | */ |
Russell King | 083be28 | 2012-05-26 14:09:53 +0100 | [diff] [blame] | 726 | spin_lock(&next->vc.lock); |
Russell King | a5a488d | 2012-05-26 13:54:15 +0100 | [diff] [blame] | 727 | /* Re-check the state now that we have the lock */ |
| 728 | success = next->state == PL08X_CHAN_WAITING; |
| 729 | if (success) |
| 730 | pl08x_phy_reassign_start(plchan->phychan, next); |
Russell King | 083be28 | 2012-05-26 14:09:53 +0100 | [diff] [blame] | 731 | spin_unlock(&next->vc.lock); |
Russell King | a5a488d | 2012-05-26 13:54:15 +0100 | [diff] [blame] | 732 | |
| 733 | /* If the state changed, try to find another channel */ |
| 734 | if (!success) |
| 735 | goto retry; |
| 736 | } else { |
| 737 | /* No more jobs, so free up the physical channel */ |
| 738 | pl08x_put_phy_channel(pl08x, plchan->phychan); |
| 739 | } |
| 740 | |
| 741 | plchan->phychan = NULL; |
| 742 | plchan->state = PL08X_CHAN_IDLE; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | /* |
| 746 | * LLI handling |
| 747 | */ |
| 748 | |
| 749 | static inline unsigned int pl08x_get_bytes_for_cctl(unsigned int coded) |
| 750 | { |
| 751 | switch (coded) { |
| 752 | case PL080_WIDTH_8BIT: |
| 753 | return 1; |
| 754 | case PL080_WIDTH_16BIT: |
| 755 | return 2; |
| 756 | case PL080_WIDTH_32BIT: |
| 757 | return 4; |
| 758 | default: |
| 759 | break; |
| 760 | } |
| 761 | BUG(); |
| 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | 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] | 766 | size_t tsize) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 767 | { |
| 768 | u32 retbits = cctl; |
| 769 | |
Russell King - ARM Linux | e8b5e11 | 2011-01-03 22:30:24 +0000 | [diff] [blame] | 770 | /* Remove all src, dst and transfer size bits */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 771 | retbits &= ~PL080_CONTROL_DWIDTH_MASK; |
| 772 | retbits &= ~PL080_CONTROL_SWIDTH_MASK; |
| 773 | retbits &= ~PL080_CONTROL_TRANSFER_SIZE_MASK; |
| 774 | |
| 775 | /* Then set the bits according to the parameters */ |
| 776 | switch (srcwidth) { |
| 777 | case 1: |
| 778 | retbits |= PL080_WIDTH_8BIT << PL080_CONTROL_SWIDTH_SHIFT; |
| 779 | break; |
| 780 | case 2: |
| 781 | retbits |= PL080_WIDTH_16BIT << PL080_CONTROL_SWIDTH_SHIFT; |
| 782 | break; |
| 783 | case 4: |
| 784 | retbits |= PL080_WIDTH_32BIT << PL080_CONTROL_SWIDTH_SHIFT; |
| 785 | break; |
| 786 | default: |
| 787 | BUG(); |
| 788 | break; |
| 789 | } |
| 790 | |
| 791 | switch (dstwidth) { |
| 792 | case 1: |
| 793 | retbits |= PL080_WIDTH_8BIT << PL080_CONTROL_DWIDTH_SHIFT; |
| 794 | break; |
| 795 | case 2: |
| 796 | retbits |= PL080_WIDTH_16BIT << PL080_CONTROL_DWIDTH_SHIFT; |
| 797 | break; |
| 798 | case 4: |
| 799 | retbits |= PL080_WIDTH_32BIT << PL080_CONTROL_DWIDTH_SHIFT; |
| 800 | break; |
| 801 | default: |
| 802 | BUG(); |
| 803 | break; |
| 804 | } |
| 805 | |
Tomasz Figa | 5110e51 | 2013-08-11 19:59:18 +0200 | [diff] [blame] | 806 | tsize &= PL080_CONTROL_TRANSFER_SIZE_MASK; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 807 | retbits |= tsize << PL080_CONTROL_TRANSFER_SIZE_SHIFT; |
| 808 | return retbits; |
| 809 | } |
| 810 | |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 811 | struct pl08x_lli_build_data { |
| 812 | struct pl08x_txd *txd; |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 813 | struct pl08x_bus_data srcbus; |
| 814 | struct pl08x_bus_data dstbus; |
| 815 | size_t remainder; |
Russell King - ARM Linux | 25c94f7 | 2011-07-21 17:11:46 +0100 | [diff] [blame] | 816 | u32 lli_bus; |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 817 | }; |
| 818 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 819 | /* |
Viresh Kumar | 0532e6f | 2011-08-05 15:32:31 +0530 | [diff] [blame] | 820 | * Autoselect a master bus to use for the transfer. Slave will be the chosen as |
| 821 | * victim in case src & dest are not similarly aligned. i.e. If after aligning |
| 822 | * masters address with width requirements of transfer (by sending few byte by |
| 823 | * byte data), slave is still not aligned, then its width will be reduced to |
| 824 | * BYTE. |
| 825 | * - prefers the destination bus if both available |
Viresh Kumar | 036f05f | 2011-08-05 15:32:41 +0530 | [diff] [blame] | 826 | * - prefers bus with fixed address (i.e. peripheral) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 827 | */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 828 | static void pl08x_choose_master_bus(struct pl08x_lli_build_data *bd, |
| 829 | struct pl08x_bus_data **mbus, struct pl08x_bus_data **sbus, u32 cctl) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 830 | { |
| 831 | if (!(cctl & PL080_CONTROL_DST_INCR)) { |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 832 | *mbus = &bd->dstbus; |
| 833 | *sbus = &bd->srcbus; |
Viresh Kumar | 036f05f | 2011-08-05 15:32:41 +0530 | [diff] [blame] | 834 | } else if (!(cctl & PL080_CONTROL_SRC_INCR)) { |
| 835 | *mbus = &bd->srcbus; |
| 836 | *sbus = &bd->dstbus; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 837 | } else { |
Viresh Kumar | 036f05f | 2011-08-05 15:32:41 +0530 | [diff] [blame] | 838 | if (bd->dstbus.buswidth >= bd->srcbus.buswidth) { |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 839 | *mbus = &bd->dstbus; |
| 840 | *sbus = &bd->srcbus; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 841 | } else { |
Viresh Kumar | 036f05f | 2011-08-05 15:32:41 +0530 | [diff] [blame] | 842 | *mbus = &bd->srcbus; |
| 843 | *sbus = &bd->dstbus; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | /* |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 849 | * 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] | 850 | */ |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 851 | static void pl08x_fill_lli_for_desc(struct pl08x_driver_data *pl08x, |
| 852 | struct pl08x_lli_build_data *bd, |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 853 | int num_llis, int len, u32 cctl, u32 cctl2) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 854 | { |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 855 | u32 offset = num_llis * pl08x->lli_words; |
| 856 | u32 *llis_va = bd->txd->llis_va + offset; |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 857 | dma_addr_t llis_bus = bd->txd->llis_bus; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 858 | |
| 859 | BUG_ON(num_llis >= MAX_NUM_TSFR_LLIS); |
| 860 | |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 861 | /* Advance the offset to next LLI. */ |
| 862 | offset += pl08x->lli_words; |
| 863 | |
| 864 | llis_va[PL080_LLI_SRC] = bd->srcbus.addr; |
| 865 | llis_va[PL080_LLI_DST] = bd->dstbus.addr; |
| 866 | llis_va[PL080_LLI_LLI] = (llis_bus + sizeof(u32) * offset); |
| 867 | llis_va[PL080_LLI_LLI] |= bd->lli_bus; |
| 868 | llis_va[PL080_LLI_CCTL] = cctl; |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 869 | if (pl08x->vd->pl080s) |
| 870 | llis_va[PL080S_LLI_CCTL2] = cctl2; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 871 | |
| 872 | if (cctl & PL080_CONTROL_SRC_INCR) |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 873 | bd->srcbus.addr += len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 874 | if (cctl & PL080_CONTROL_DST_INCR) |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 875 | bd->dstbus.addr += len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 876 | |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 877 | BUG_ON(bd->remainder < len); |
Russell King - ARM Linux | cace658 | 2011-01-03 22:37:31 +0000 | [diff] [blame] | 878 | |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 879 | bd->remainder -= len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 880 | } |
| 881 | |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 882 | static inline void prep_byte_width_lli(struct pl08x_driver_data *pl08x, |
| 883 | struct pl08x_lli_build_data *bd, u32 *cctl, u32 len, |
| 884 | int num_llis, size_t *total_bytes) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 885 | { |
Viresh Kumar | 03af500 | 2011-08-05 15:32:39 +0530 | [diff] [blame] | 886 | *cctl = pl08x_cctl_bits(*cctl, 1, 1, len); |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 887 | pl08x_fill_lli_for_desc(pl08x, bd, num_llis, len, *cctl, len); |
Viresh Kumar | 03af500 | 2011-08-05 15:32:39 +0530 | [diff] [blame] | 888 | (*total_bytes) += len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 889 | } |
| 890 | |
Tomasz Figa | 48924e4 | 2013-08-11 19:59:16 +0200 | [diff] [blame] | 891 | #ifdef VERBOSE_DEBUG |
| 892 | static void pl08x_dump_lli(struct pl08x_driver_data *pl08x, |
| 893 | const u32 *llis_va, int num_llis) |
| 894 | { |
| 895 | int i; |
| 896 | |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 897 | if (pl08x->vd->pl080s) { |
Tomasz Figa | 48924e4 | 2013-08-11 19:59:16 +0200 | [diff] [blame] | 898 | dev_vdbg(&pl08x->adev->dev, |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 899 | "%-3s %-9s %-10s %-10s %-10s %-10s %s\n", |
| 900 | "lli", "", "csrc", "cdst", "clli", "cctl", "cctl2"); |
| 901 | for (i = 0; i < num_llis; i++) { |
| 902 | dev_vdbg(&pl08x->adev->dev, |
| 903 | "%3d @%p: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", |
| 904 | i, llis_va, llis_va[PL080_LLI_SRC], |
| 905 | llis_va[PL080_LLI_DST], llis_va[PL080_LLI_LLI], |
| 906 | llis_va[PL080_LLI_CCTL], |
| 907 | llis_va[PL080S_LLI_CCTL2]); |
| 908 | llis_va += pl08x->lli_words; |
| 909 | } |
| 910 | } else { |
| 911 | dev_vdbg(&pl08x->adev->dev, |
| 912 | "%-3s %-9s %-10s %-10s %-10s %s\n", |
| 913 | "lli", "", "csrc", "cdst", "clli", "cctl"); |
| 914 | for (i = 0; i < num_llis; i++) { |
| 915 | dev_vdbg(&pl08x->adev->dev, |
| 916 | "%3d @%p: 0x%08x 0x%08x 0x%08x 0x%08x\n", |
| 917 | i, llis_va, llis_va[PL080_LLI_SRC], |
| 918 | llis_va[PL080_LLI_DST], llis_va[PL080_LLI_LLI], |
| 919 | llis_va[PL080_LLI_CCTL]); |
| 920 | llis_va += pl08x->lli_words; |
| 921 | } |
Tomasz Figa | 48924e4 | 2013-08-11 19:59:16 +0200 | [diff] [blame] | 922 | } |
| 923 | } |
| 924 | #else |
| 925 | static inline void pl08x_dump_lli(struct pl08x_driver_data *pl08x, |
| 926 | const u32 *llis_va, int num_llis) {} |
| 927 | #endif |
| 928 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 929 | /* |
| 930 | * This fills in the table of LLIs for the transfer descriptor |
| 931 | * Note that we assume we never have to change the burst sizes |
| 932 | * Return 0 for error |
| 933 | */ |
| 934 | static int pl08x_fill_llis_for_desc(struct pl08x_driver_data *pl08x, |
| 935 | struct pl08x_txd *txd) |
| 936 | { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 937 | struct pl08x_bus_data *mbus, *sbus; |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 938 | struct pl08x_lli_build_data bd; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 939 | int num_llis = 0; |
Viresh Kumar | 03af500 | 2011-08-05 15:32:39 +0530 | [diff] [blame] | 940 | u32 cctl, early_bytes = 0; |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 941 | size_t max_bytes_per_lli, total_bytes; |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 942 | u32 *llis_va, *last_lli; |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 943 | struct pl08x_sg *dsg; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 944 | |
Viresh Kumar | 3e27ee8 | 2011-08-05 15:32:27 +0530 | [diff] [blame] | 945 | txd->llis_va = dma_pool_alloc(pl08x->pool, GFP_NOWAIT, &txd->llis_bus); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 946 | if (!txd->llis_va) { |
| 947 | dev_err(&pl08x->adev->dev, "%s no memory for llis\n", __func__); |
| 948 | return 0; |
| 949 | } |
| 950 | |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 951 | bd.txd = txd; |
Russell King - ARM Linux | 25c94f7 | 2011-07-21 17:11:46 +0100 | [diff] [blame] | 952 | bd.lli_bus = (pl08x->lli_buses & PL08X_AHB2) ? PL080_LLI_LM_AHB2 : 0; |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 953 | cctl = txd->cctl; |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 954 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 955 | /* Find maximum width of the source bus */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 956 | bd.srcbus.maxwidth = |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 957 | pl08x_get_bytes_for_cctl((cctl & PL080_CONTROL_SWIDTH_MASK) >> |
| 958 | PL080_CONTROL_SWIDTH_SHIFT); |
| 959 | |
| 960 | /* Find maximum width of the destination bus */ |
Russell King - ARM Linux | 542361f | 2011-01-03 22:43:15 +0000 | [diff] [blame] | 961 | bd.dstbus.maxwidth = |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 962 | pl08x_get_bytes_for_cctl((cctl & PL080_CONTROL_DWIDTH_MASK) >> |
| 963 | PL080_CONTROL_DWIDTH_SHIFT); |
| 964 | |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 965 | list_for_each_entry(dsg, &txd->dsg_list, node) { |
| 966 | total_bytes = 0; |
| 967 | cctl = txd->cctl; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 968 | |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 969 | bd.srcbus.addr = dsg->src_addr; |
| 970 | bd.dstbus.addr = dsg->dst_addr; |
| 971 | bd.remainder = dsg->len; |
| 972 | bd.srcbus.buswidth = bd.srcbus.maxwidth; |
| 973 | bd.dstbus.buswidth = bd.dstbus.maxwidth; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 974 | |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 975 | pl08x_choose_master_bus(&bd, &mbus, &sbus, cctl); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 976 | |
Andre Przywara | b90ca06 | 2013-08-14 14:52:09 +0200 | [diff] [blame] | 977 | dev_vdbg(&pl08x->adev->dev, |
| 978 | "src=0x%08llx%s/%u dst=0x%08llx%s/%u len=%zu\n", |
| 979 | (u64)bd.srcbus.addr, |
| 980 | cctl & PL080_CONTROL_SRC_INCR ? "+" : "", |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 981 | bd.srcbus.buswidth, |
Andre Przywara | b90ca06 | 2013-08-14 14:52:09 +0200 | [diff] [blame] | 982 | (u64)bd.dstbus.addr, |
| 983 | cctl & PL080_CONTROL_DST_INCR ? "+" : "", |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 984 | bd.dstbus.buswidth, |
| 985 | bd.remainder); |
| 986 | dev_vdbg(&pl08x->adev->dev, "mbus=%s sbus=%s\n", |
| 987 | mbus == &bd.srcbus ? "src" : "dst", |
| 988 | sbus == &bd.srcbus ? "src" : "dst"); |
Russell King - ARM Linux | fc74eb7 | 2011-07-21 17:12:06 +0100 | [diff] [blame] | 989 | |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 990 | /* |
| 991 | * Zero length is only allowed if all these requirements are |
| 992 | * met: |
| 993 | * - flow controller is peripheral. |
| 994 | * - src.addr is aligned to src.width |
| 995 | * - dst.addr is aligned to dst.width |
| 996 | * |
| 997 | * sg_len == 1 should be true, as there can be two cases here: |
| 998 | * |
| 999 | * - Memory addresses are contiguous and are not scattered. |
| 1000 | * Here, Only one sg will be passed by user driver, with |
| 1001 | * memory address and zero length. We pass this to controller |
| 1002 | * and after the transfer it will receive the last burst |
| 1003 | * request from peripheral and so transfer finishes. |
| 1004 | * |
| 1005 | * - Memory addresses are scattered and are not contiguous. |
| 1006 | * Here, Obviously as DMA controller doesn't know when a lli's |
| 1007 | * transfer gets over, it can't load next lli. So in this |
| 1008 | * case, there has to be an assumption that only one lli is |
| 1009 | * supported. Thus, we can't have scattered addresses. |
| 1010 | */ |
| 1011 | if (!bd.remainder) { |
| 1012 | u32 fc = (txd->ccfg & PL080_CONFIG_FLOW_CONTROL_MASK) >> |
| 1013 | PL080_CONFIG_FLOW_CONTROL_SHIFT; |
| 1014 | if (!((fc >= PL080_FLOW_SRC2DST_DST) && |
Viresh Kumar | 0a23565 | 2011-08-05 15:32:42 +0530 | [diff] [blame] | 1015 | (fc <= PL080_FLOW_SRC2DST_SRC))) { |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1016 | dev_err(&pl08x->adev->dev, "%s sg len can't be zero", |
| 1017 | __func__); |
| 1018 | return 0; |
| 1019 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1020 | |
Andre Przywara | 1c38b28 | 2013-08-19 12:19:28 +0200 | [diff] [blame] | 1021 | if (!IS_BUS_ALIGNED(&bd.srcbus) || |
| 1022 | !IS_BUS_ALIGNED(&bd.dstbus)) { |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1023 | dev_err(&pl08x->adev->dev, |
| 1024 | "%s src & dst address must be aligned to src" |
| 1025 | " & dst width if peripheral is flow controller", |
| 1026 | __func__); |
| 1027 | return 0; |
| 1028 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1029 | |
Viresh Kumar | 16a2e7d | 2011-08-05 15:32:37 +0530 | [diff] [blame] | 1030 | cctl = pl08x_cctl_bits(cctl, bd.srcbus.buswidth, |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1031 | bd.dstbus.buswidth, 0); |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 1032 | pl08x_fill_lli_for_desc(pl08x, &bd, num_llis++, |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 1033 | 0, cctl, 0); |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1034 | break; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | /* |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1038 | * Send byte by byte for following cases |
| 1039 | * - Less than a bus width available |
| 1040 | * - until master bus is aligned |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1041 | */ |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1042 | if (bd.remainder < mbus->buswidth) |
| 1043 | early_bytes = bd.remainder; |
Andre Przywara | 1c38b28 | 2013-08-19 12:19:28 +0200 | [diff] [blame] | 1044 | else if (!IS_BUS_ALIGNED(mbus)) { |
| 1045 | early_bytes = mbus->buswidth - |
| 1046 | (mbus->addr & (mbus->buswidth - 1)); |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1047 | if ((bd.remainder - early_bytes) < mbus->buswidth) |
| 1048 | early_bytes = bd.remainder; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1049 | } |
Viresh Kumar | 16a2e7d | 2011-08-05 15:32:37 +0530 | [diff] [blame] | 1050 | |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1051 | if (early_bytes) { |
| 1052 | dev_vdbg(&pl08x->adev->dev, |
Mark Brown | 6fc8ae7 | 2014-08-01 18:09:48 +0100 | [diff] [blame] | 1053 | "%s byte width LLIs (remain 0x%08zx)\n", |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1054 | __func__, bd.remainder); |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 1055 | prep_byte_width_lli(pl08x, &bd, &cctl, early_bytes, |
| 1056 | num_llis++, &total_bytes); |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1057 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1058 | |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1059 | if (bd.remainder) { |
| 1060 | /* |
| 1061 | * Master now aligned |
| 1062 | * - if slave is not then we must set its width down |
| 1063 | */ |
Andre Przywara | 1c38b28 | 2013-08-19 12:19:28 +0200 | [diff] [blame] | 1064 | if (!IS_BUS_ALIGNED(sbus)) { |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1065 | dev_dbg(&pl08x->adev->dev, |
| 1066 | "%s set down bus width to one byte\n", |
| 1067 | __func__); |
| 1068 | |
| 1069 | sbus->buswidth = 1; |
| 1070 | } |
| 1071 | |
| 1072 | /* |
| 1073 | * Bytes transferred = tsize * src width, not |
| 1074 | * MIN(buswidths) |
| 1075 | */ |
| 1076 | max_bytes_per_lli = bd.srcbus.buswidth * |
Tomasz Figa | 5110e51 | 2013-08-11 19:59:18 +0200 | [diff] [blame] | 1077 | pl08x->vd->max_transfer_size; |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1078 | dev_vdbg(&pl08x->adev->dev, |
| 1079 | "%s max bytes per lli = %zu\n", |
| 1080 | __func__, max_bytes_per_lli); |
| 1081 | |
| 1082 | /* |
| 1083 | * Make largest possible LLIs until less than one bus |
| 1084 | * width left |
| 1085 | */ |
| 1086 | while (bd.remainder > (mbus->buswidth - 1)) { |
| 1087 | size_t lli_len, tsize, width; |
| 1088 | |
| 1089 | /* |
| 1090 | * If enough left try to send max possible, |
| 1091 | * otherwise try to send the remainder |
| 1092 | */ |
| 1093 | lli_len = min(bd.remainder, max_bytes_per_lli); |
| 1094 | |
| 1095 | /* |
| 1096 | * Check against maximum bus alignment: |
| 1097 | * Calculate actual transfer size in relation to |
| 1098 | * bus width an get a maximum remainder of the |
| 1099 | * highest bus width - 1 |
| 1100 | */ |
| 1101 | width = max(mbus->buswidth, sbus->buswidth); |
| 1102 | lli_len = (lli_len / width) * width; |
| 1103 | tsize = lli_len / bd.srcbus.buswidth; |
| 1104 | |
| 1105 | dev_vdbg(&pl08x->adev->dev, |
| 1106 | "%s fill lli with single lli chunk of " |
| 1107 | "size 0x%08zx (remainder 0x%08zx)\n", |
| 1108 | __func__, lli_len, bd.remainder); |
| 1109 | |
| 1110 | cctl = pl08x_cctl_bits(cctl, bd.srcbus.buswidth, |
| 1111 | bd.dstbus.buswidth, tsize); |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 1112 | pl08x_fill_lli_for_desc(pl08x, &bd, num_llis++, |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 1113 | lli_len, cctl, tsize); |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1114 | total_bytes += lli_len; |
| 1115 | } |
| 1116 | |
| 1117 | /* |
| 1118 | * Send any odd bytes |
| 1119 | */ |
| 1120 | if (bd.remainder) { |
| 1121 | dev_vdbg(&pl08x->adev->dev, |
| 1122 | "%s align with boundary, send odd bytes (remain %zu)\n", |
| 1123 | __func__, bd.remainder); |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 1124 | prep_byte_width_lli(pl08x, &bd, &cctl, |
| 1125 | bd.remainder, num_llis++, &total_bytes); |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | if (total_bytes != dsg->len) { |
| 1130 | dev_err(&pl08x->adev->dev, |
| 1131 | "%s size of encoded lli:s don't match total txd, transferred 0x%08zx from size 0x%08zx\n", |
| 1132 | __func__, total_bytes, dsg->len); |
| 1133 | return 0; |
| 1134 | } |
| 1135 | |
| 1136 | if (num_llis >= MAX_NUM_TSFR_LLIS) { |
| 1137 | dev_err(&pl08x->adev->dev, |
| 1138 | "%s need to increase MAX_NUM_TSFR_LLIS from 0x%08x\n", |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 1139 | __func__, MAX_NUM_TSFR_LLIS); |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1140 | return 0; |
| 1141 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1142 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1143 | |
Russell King - ARM Linux | b58b6b5 | 2011-01-03 22:34:48 +0000 | [diff] [blame] | 1144 | llis_va = txd->llis_va; |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 1145 | last_lli = llis_va + (num_llis - 1) * pl08x->lli_words; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1146 | |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 1147 | if (txd->cyclic) { |
| 1148 | /* Link back to the first LLI. */ |
| 1149 | last_lli[PL080_LLI_LLI] = txd->llis_bus | bd.lli_bus; |
| 1150 | } else { |
| 1151 | /* The final LLI terminates the LLI. */ |
| 1152 | last_lli[PL080_LLI_LLI] = 0; |
| 1153 | /* The final LLI element shall also fire an interrupt. */ |
| 1154 | last_lli[PL080_LLI_CCTL] |= PL080_CONTROL_TC_IRQ_EN; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1155 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1156 | |
Tomasz Figa | 48924e4 | 2013-08-11 19:59:16 +0200 | [diff] [blame] | 1157 | pl08x_dump_lli(pl08x, llis_va, num_llis); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1158 | |
| 1159 | return num_llis; |
| 1160 | } |
| 1161 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1162 | static void pl08x_free_txd(struct pl08x_driver_data *pl08x, |
| 1163 | struct pl08x_txd *txd) |
| 1164 | { |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1165 | struct pl08x_sg *dsg, *_dsg; |
| 1166 | |
Viresh Kumar | c120564 | 2011-08-05 15:32:44 +0530 | [diff] [blame] | 1167 | if (txd->llis_va) |
| 1168 | dma_pool_free(pl08x->pool, txd->llis_va, txd->llis_bus); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1169 | |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1170 | list_for_each_entry_safe(dsg, _dsg, &txd->dsg_list, node) { |
| 1171 | list_del(&dsg->node); |
| 1172 | kfree(dsg); |
| 1173 | } |
| 1174 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1175 | kfree(txd); |
| 1176 | } |
| 1177 | |
Russell King | 1853613 | 2012-05-26 14:42:23 +0100 | [diff] [blame] | 1178 | static void pl08x_desc_free(struct virt_dma_desc *vd) |
| 1179 | { |
| 1180 | struct pl08x_txd *txd = to_pl08x_txd(&vd->tx); |
| 1181 | struct pl08x_dma_chan *plchan = to_pl08x_chan(vd->tx.chan); |
Russell King | 1853613 | 2012-05-26 14:42:23 +0100 | [diff] [blame] | 1182 | |
Russell King - ARM Linux | 89116bf | 2013-11-26 16:03:03 -0800 | [diff] [blame] | 1183 | dma_descriptor_unmap(&vd->tx); |
Russell King | 1853613 | 2012-05-26 14:42:23 +0100 | [diff] [blame] | 1184 | if (!txd->done) |
| 1185 | pl08x_release_mux(plchan); |
| 1186 | |
Russell King | 1853613 | 2012-05-26 14:42:23 +0100 | [diff] [blame] | 1187 | pl08x_free_txd(plchan->host, txd); |
Russell King | 1853613 | 2012-05-26 14:42:23 +0100 | [diff] [blame] | 1188 | } |
| 1189 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1190 | static void pl08x_free_txd_list(struct pl08x_driver_data *pl08x, |
| 1191 | struct pl08x_dma_chan *plchan) |
| 1192 | { |
Russell King | ea16056 | 2012-05-25 13:10:36 +0100 | [diff] [blame] | 1193 | LIST_HEAD(head); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1194 | |
Russell King | 879f127 | 2012-05-26 14:27:40 +0100 | [diff] [blame] | 1195 | vchan_get_all_descriptors(&plchan->vc, &head); |
Akinobu Mita | 9199826 | 2012-10-28 00:49:31 +0900 | [diff] [blame] | 1196 | vchan_dma_desc_free_list(&plchan->vc, &head); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | /* |
| 1200 | * The DMA ENGINE API |
| 1201 | */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1202 | static void pl08x_free_chan_resources(struct dma_chan *chan) |
| 1203 | { |
Russell King | a068682 | 2012-05-26 17:00:49 +0100 | [diff] [blame] | 1204 | /* Ensure all queued descriptors are freed */ |
| 1205 | vchan_free_chan_resources(to_virt_chan(chan)); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1206 | } |
| 1207 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1208 | static struct dma_async_tx_descriptor *pl08x_prep_dma_interrupt( |
| 1209 | struct dma_chan *chan, unsigned long flags) |
| 1210 | { |
| 1211 | struct dma_async_tx_descriptor *retval = NULL; |
| 1212 | |
| 1213 | return retval; |
| 1214 | } |
| 1215 | |
| 1216 | /* |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1217 | * Code accessing dma_async_is_complete() in a tight loop may give problems. |
| 1218 | * If slaves are relying on interrupts to signal completion this function |
| 1219 | * must not be called with interrupts disabled. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1220 | */ |
Viresh Kumar | 3e27ee8 | 2011-08-05 15:32:27 +0530 | [diff] [blame] | 1221 | static enum dma_status pl08x_dma_tx_status(struct dma_chan *chan, |
| 1222 | dma_cookie_t cookie, struct dma_tx_state *txstate) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1223 | { |
| 1224 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
Russell King | 06e885b | 2012-05-26 15:05:52 +0100 | [diff] [blame] | 1225 | struct virt_dma_desc *vd; |
| 1226 | unsigned long flags; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1227 | enum dma_status ret; |
Russell King | 06e885b | 2012-05-26 15:05:52 +0100 | [diff] [blame] | 1228 | size_t bytes = 0; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1229 | |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 1230 | ret = dma_cookie_status(chan, cookie, txstate); |
Vinod Koul | 0996e89 | 2013-10-16 13:33:02 +0530 | [diff] [blame] | 1231 | if (ret == DMA_COMPLETE) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1232 | return ret; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1233 | |
| 1234 | /* |
Russell King | 06e885b | 2012-05-26 15:05:52 +0100 | [diff] [blame] | 1235 | * There's no point calculating the residue if there's |
| 1236 | * no txstate to store the value. |
| 1237 | */ |
| 1238 | if (!txstate) { |
| 1239 | if (plchan->state == PL08X_CHAN_PAUSED) |
| 1240 | ret = DMA_PAUSED; |
| 1241 | return ret; |
| 1242 | } |
| 1243 | |
| 1244 | spin_lock_irqsave(&plchan->vc.lock, flags); |
| 1245 | ret = dma_cookie_status(chan, cookie, txstate); |
Vinod Koul | 0996e89 | 2013-10-16 13:33:02 +0530 | [diff] [blame] | 1246 | if (ret != DMA_COMPLETE) { |
Russell King | 06e885b | 2012-05-26 15:05:52 +0100 | [diff] [blame] | 1247 | vd = vchan_find_desc(&plchan->vc, cookie); |
| 1248 | if (vd) { |
| 1249 | /* On the issued list, so hasn't been processed yet */ |
| 1250 | struct pl08x_txd *txd = to_pl08x_txd(&vd->tx); |
| 1251 | struct pl08x_sg *dsg; |
| 1252 | |
| 1253 | list_for_each_entry(dsg, &txd->dsg_list, node) |
| 1254 | bytes += dsg->len; |
| 1255 | } else { |
| 1256 | bytes = pl08x_getbytes_chan(plchan); |
| 1257 | } |
| 1258 | } |
| 1259 | spin_unlock_irqrestore(&plchan->vc.lock, flags); |
| 1260 | |
| 1261 | /* |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1262 | * This cookie not complete yet |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 1263 | * Get number of bytes left in the active transactions and queue |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1264 | */ |
Russell King | 06e885b | 2012-05-26 15:05:52 +0100 | [diff] [blame] | 1265 | dma_set_residue(txstate, bytes); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1266 | |
Russell King | 06e885b | 2012-05-26 15:05:52 +0100 | [diff] [blame] | 1267 | if (plchan->state == PL08X_CHAN_PAUSED && ret == DMA_IN_PROGRESS) |
| 1268 | ret = DMA_PAUSED; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1269 | |
| 1270 | /* Whether waiting or running, we're in progress */ |
Russell King | 06e885b | 2012-05-26 15:05:52 +0100 | [diff] [blame] | 1271 | return ret; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | /* PrimeCell DMA extension */ |
| 1275 | struct burst_table { |
Russell King - ARM Linux | 760596c6 | 2011-07-21 17:14:08 +0100 | [diff] [blame] | 1276 | u32 burstwords; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1277 | u32 reg; |
| 1278 | }; |
| 1279 | |
| 1280 | static const struct burst_table burst_sizes[] = { |
| 1281 | { |
| 1282 | .burstwords = 256, |
Russell King - ARM Linux | 760596c6 | 2011-07-21 17:14:08 +0100 | [diff] [blame] | 1283 | .reg = PL080_BSIZE_256, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1284 | }, |
| 1285 | { |
| 1286 | .burstwords = 128, |
Russell King - ARM Linux | 760596c6 | 2011-07-21 17:14:08 +0100 | [diff] [blame] | 1287 | .reg = PL080_BSIZE_128, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1288 | }, |
| 1289 | { |
| 1290 | .burstwords = 64, |
Russell King - ARM Linux | 760596c6 | 2011-07-21 17:14:08 +0100 | [diff] [blame] | 1291 | .reg = PL080_BSIZE_64, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1292 | }, |
| 1293 | { |
| 1294 | .burstwords = 32, |
Russell King - ARM Linux | 760596c6 | 2011-07-21 17:14:08 +0100 | [diff] [blame] | 1295 | .reg = PL080_BSIZE_32, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1296 | }, |
| 1297 | { |
| 1298 | .burstwords = 16, |
Russell King - ARM Linux | 760596c6 | 2011-07-21 17:14:08 +0100 | [diff] [blame] | 1299 | .reg = PL080_BSIZE_16, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1300 | }, |
| 1301 | { |
| 1302 | .burstwords = 8, |
Russell King - ARM Linux | 760596c6 | 2011-07-21 17:14:08 +0100 | [diff] [blame] | 1303 | .reg = PL080_BSIZE_8, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1304 | }, |
| 1305 | { |
| 1306 | .burstwords = 4, |
Russell King - ARM Linux | 760596c6 | 2011-07-21 17:14:08 +0100 | [diff] [blame] | 1307 | .reg = PL080_BSIZE_4, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1308 | }, |
| 1309 | { |
Russell King - ARM Linux | 760596c6 | 2011-07-21 17:14:08 +0100 | [diff] [blame] | 1310 | .burstwords = 0, |
| 1311 | .reg = PL080_BSIZE_1, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1312 | }, |
| 1313 | }; |
| 1314 | |
Russell King - ARM Linux | 121c847 | 2011-07-21 17:13:48 +0100 | [diff] [blame] | 1315 | /* |
| 1316 | * Given the source and destination available bus masks, select which |
| 1317 | * will be routed to each port. We try to have source and destination |
| 1318 | * on separate ports, but always respect the allowable settings. |
| 1319 | */ |
| 1320 | static u32 pl08x_select_bus(u8 src, u8 dst) |
| 1321 | { |
| 1322 | u32 cctl = 0; |
| 1323 | |
| 1324 | if (!(dst & PL08X_AHB1) || ((dst & PL08X_AHB2) && (src & PL08X_AHB1))) |
| 1325 | cctl |= PL080_CONTROL_DST_AHB2; |
| 1326 | if (!(src & PL08X_AHB1) || ((src & PL08X_AHB2) && !(dst & PL08X_AHB2))) |
| 1327 | cctl |= PL080_CONTROL_SRC_AHB2; |
| 1328 | |
| 1329 | return cctl; |
| 1330 | } |
| 1331 | |
Russell King - ARM Linux | f14c426 | 2011-07-21 17:12:47 +0100 | [diff] [blame] | 1332 | static u32 pl08x_cctl(u32 cctl) |
| 1333 | { |
| 1334 | cctl &= ~(PL080_CONTROL_SRC_AHB2 | PL080_CONTROL_DST_AHB2 | |
| 1335 | PL080_CONTROL_SRC_INCR | PL080_CONTROL_DST_INCR | |
| 1336 | PL080_CONTROL_PROT_MASK); |
| 1337 | |
| 1338 | /* Access the cell in privileged mode, non-bufferable, non-cacheable */ |
| 1339 | return cctl | PL080_CONTROL_PROT_SYS; |
| 1340 | } |
| 1341 | |
Russell King - ARM Linux | aa88cda | 2011-07-21 17:13:28 +0100 | [diff] [blame] | 1342 | static u32 pl08x_width(enum dma_slave_buswidth width) |
| 1343 | { |
| 1344 | switch (width) { |
| 1345 | case DMA_SLAVE_BUSWIDTH_1_BYTE: |
| 1346 | return PL080_WIDTH_8BIT; |
| 1347 | case DMA_SLAVE_BUSWIDTH_2_BYTES: |
| 1348 | return PL080_WIDTH_16BIT; |
| 1349 | case DMA_SLAVE_BUSWIDTH_4_BYTES: |
| 1350 | return PL080_WIDTH_32BIT; |
Vinod Koul | f32807f | 2011-07-25 19:22:01 +0530 | [diff] [blame] | 1351 | default: |
| 1352 | return ~0; |
Russell King - ARM Linux | aa88cda | 2011-07-21 17:13:28 +0100 | [diff] [blame] | 1353 | } |
Russell King - ARM Linux | aa88cda | 2011-07-21 17:13:28 +0100 | [diff] [blame] | 1354 | } |
| 1355 | |
Russell King - ARM Linux | 760596c6 | 2011-07-21 17:14:08 +0100 | [diff] [blame] | 1356 | static u32 pl08x_burst(u32 maxburst) |
| 1357 | { |
| 1358 | int i; |
| 1359 | |
| 1360 | for (i = 0; i < ARRAY_SIZE(burst_sizes); i++) |
| 1361 | if (burst_sizes[i].burstwords <= maxburst) |
| 1362 | break; |
| 1363 | |
| 1364 | return burst_sizes[i].reg; |
| 1365 | } |
| 1366 | |
Russell King | 9862ba1 | 2012-05-16 11:16:03 +0100 | [diff] [blame] | 1367 | static u32 pl08x_get_cctl(struct pl08x_dma_chan *plchan, |
| 1368 | enum dma_slave_buswidth addr_width, u32 maxburst) |
| 1369 | { |
| 1370 | u32 width, burst, cctl = 0; |
| 1371 | |
| 1372 | width = pl08x_width(addr_width); |
| 1373 | if (width == ~0) |
| 1374 | return ~0; |
| 1375 | |
| 1376 | cctl |= width << PL080_CONTROL_SWIDTH_SHIFT; |
| 1377 | cctl |= width << PL080_CONTROL_DWIDTH_SHIFT; |
| 1378 | |
| 1379 | /* |
| 1380 | * If this channel will only request single transfers, set this |
| 1381 | * down to ONE element. Also select one element if no maxburst |
| 1382 | * is specified. |
| 1383 | */ |
| 1384 | if (plchan->cd->single) |
| 1385 | maxburst = 1; |
| 1386 | |
| 1387 | burst = pl08x_burst(maxburst); |
| 1388 | cctl |= burst << PL080_CONTROL_SB_SIZE_SHIFT; |
| 1389 | cctl |= burst << PL080_CONTROL_DB_SIZE_SHIFT; |
| 1390 | |
| 1391 | return pl08x_cctl(cctl); |
| 1392 | } |
| 1393 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1394 | /* |
| 1395 | * Slave transactions callback to the slave device to allow |
| 1396 | * synchronization of slave DMA signals with the DMAC enable |
| 1397 | */ |
| 1398 | static void pl08x_issue_pending(struct dma_chan *chan) |
| 1399 | { |
| 1400 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1401 | unsigned long flags; |
| 1402 | |
Russell King | 083be28 | 2012-05-26 14:09:53 +0100 | [diff] [blame] | 1403 | spin_lock_irqsave(&plchan->vc.lock, flags); |
Russell King | 879f127 | 2012-05-26 14:27:40 +0100 | [diff] [blame] | 1404 | if (vchan_issue_pending(&plchan->vc)) { |
Russell King | a5a488d | 2012-05-26 13:54:15 +0100 | [diff] [blame] | 1405 | if (!plchan->phychan && plchan->state != PL08X_CHAN_WAITING) |
| 1406 | pl08x_phy_alloc_and_start(plchan); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1407 | } |
Russell King | 083be28 | 2012-05-26 14:09:53 +0100 | [diff] [blame] | 1408 | spin_unlock_irqrestore(&plchan->vc.lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1409 | } |
| 1410 | |
Russell King | 879f127 | 2012-05-26 14:27:40 +0100 | [diff] [blame] | 1411 | static struct pl08x_txd *pl08x_get_txd(struct pl08x_dma_chan *plchan) |
Russell King - ARM Linux | ac3cd20 | 2011-01-03 22:35:49 +0000 | [diff] [blame] | 1412 | { |
Viresh Kumar | b201c11 | 2011-08-05 15:32:29 +0530 | [diff] [blame] | 1413 | struct pl08x_txd *txd = kzalloc(sizeof(*txd), GFP_NOWAIT); |
Russell King - ARM Linux | ac3cd20 | 2011-01-03 22:35:49 +0000 | [diff] [blame] | 1414 | |
| 1415 | if (txd) { |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1416 | INIT_LIST_HEAD(&txd->dsg_list); |
Russell King - ARM Linux | 4983a04 | 2011-01-03 22:39:33 +0000 | [diff] [blame] | 1417 | |
| 1418 | /* Always enable error and terminal interrupts */ |
| 1419 | txd->ccfg = PL080_CONFIG_ERR_IRQ_MASK | |
| 1420 | PL080_CONFIG_TC_IRQ_MASK; |
Russell King - ARM Linux | ac3cd20 | 2011-01-03 22:35:49 +0000 | [diff] [blame] | 1421 | } |
| 1422 | return txd; |
| 1423 | } |
| 1424 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1425 | /* |
| 1426 | * Initialize a descriptor to be used by memcpy submit |
| 1427 | */ |
| 1428 | static struct dma_async_tx_descriptor *pl08x_prep_dma_memcpy( |
| 1429 | struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, |
| 1430 | size_t len, unsigned long flags) |
| 1431 | { |
| 1432 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1433 | struct pl08x_driver_data *pl08x = plchan->host; |
| 1434 | struct pl08x_txd *txd; |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1435 | struct pl08x_sg *dsg; |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 1436 | u32 cctl = 0; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1437 | int ret; |
| 1438 | |
Russell King | 879f127 | 2012-05-26 14:27:40 +0100 | [diff] [blame] | 1439 | txd = pl08x_get_txd(plchan); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1440 | if (!txd) { |
| 1441 | dev_err(&pl08x->adev->dev, |
| 1442 | "%s no memory for descriptor\n", __func__); |
| 1443 | return NULL; |
| 1444 | } |
| 1445 | |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1446 | dsg = kzalloc(sizeof(struct pl08x_sg), GFP_NOWAIT); |
| 1447 | if (!dsg) { |
| 1448 | pl08x_free_txd(pl08x, txd); |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1449 | return NULL; |
| 1450 | } |
| 1451 | list_add_tail(&dsg->node, &txd->dsg_list); |
| 1452 | |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1453 | dsg->src_addr = src; |
| 1454 | dsg->dst_addr = dest; |
| 1455 | dsg->len = len; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1456 | |
| 1457 | /* Set platform data for m2m */ |
Russell King - ARM Linux | 4983a04 | 2011-01-03 22:39:33 +0000 | [diff] [blame] | 1458 | txd->ccfg |= PL080_FLOW_MEM2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT; |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 1459 | |
| 1460 | /* Conjure cctl */ |
| 1461 | switch (pl08x->pd->memcpy_burst_size) { |
| 1462 | default: |
| 1463 | dev_err(&pl08x->adev->dev, |
| 1464 | "illegal burst size for memcpy, set to 1\n"); |
| 1465 | /* Fall through */ |
| 1466 | case PL08X_BURST_SZ_1: |
| 1467 | cctl |= PL080_BSIZE_1 << PL080_CONTROL_SB_SIZE_SHIFT | |
| 1468 | PL080_BSIZE_1 << PL080_CONTROL_DB_SIZE_SHIFT; |
| 1469 | break; |
| 1470 | case PL08X_BURST_SZ_4: |
| 1471 | cctl |= PL080_BSIZE_4 << PL080_CONTROL_SB_SIZE_SHIFT | |
| 1472 | PL080_BSIZE_4 << PL080_CONTROL_DB_SIZE_SHIFT; |
| 1473 | break; |
| 1474 | case PL08X_BURST_SZ_8: |
| 1475 | cctl |= PL080_BSIZE_8 << PL080_CONTROL_SB_SIZE_SHIFT | |
| 1476 | PL080_BSIZE_8 << PL080_CONTROL_DB_SIZE_SHIFT; |
| 1477 | break; |
| 1478 | case PL08X_BURST_SZ_16: |
| 1479 | cctl |= PL080_BSIZE_16 << PL080_CONTROL_SB_SIZE_SHIFT | |
| 1480 | PL080_BSIZE_16 << PL080_CONTROL_DB_SIZE_SHIFT; |
| 1481 | break; |
| 1482 | case PL08X_BURST_SZ_32: |
| 1483 | cctl |= PL080_BSIZE_32 << PL080_CONTROL_SB_SIZE_SHIFT | |
| 1484 | PL080_BSIZE_32 << PL080_CONTROL_DB_SIZE_SHIFT; |
| 1485 | break; |
| 1486 | case PL08X_BURST_SZ_64: |
| 1487 | cctl |= PL080_BSIZE_64 << PL080_CONTROL_SB_SIZE_SHIFT | |
| 1488 | PL080_BSIZE_64 << PL080_CONTROL_DB_SIZE_SHIFT; |
| 1489 | break; |
| 1490 | case PL08X_BURST_SZ_128: |
| 1491 | cctl |= PL080_BSIZE_128 << PL080_CONTROL_SB_SIZE_SHIFT | |
| 1492 | PL080_BSIZE_128 << PL080_CONTROL_DB_SIZE_SHIFT; |
| 1493 | break; |
| 1494 | case PL08X_BURST_SZ_256: |
| 1495 | cctl |= PL080_BSIZE_256 << PL080_CONTROL_SB_SIZE_SHIFT | |
| 1496 | PL080_BSIZE_256 << PL080_CONTROL_DB_SIZE_SHIFT; |
| 1497 | break; |
| 1498 | } |
| 1499 | |
| 1500 | switch (pl08x->pd->memcpy_bus_width) { |
| 1501 | default: |
| 1502 | dev_err(&pl08x->adev->dev, |
| 1503 | "illegal bus width for memcpy, set to 8 bits\n"); |
| 1504 | /* Fall through */ |
| 1505 | case PL08X_BUS_WIDTH_8_BITS: |
| 1506 | cctl |= PL080_WIDTH_8BIT << PL080_CONTROL_SWIDTH_SHIFT | |
| 1507 | PL080_WIDTH_8BIT << PL080_CONTROL_DWIDTH_SHIFT; |
| 1508 | break; |
| 1509 | case PL08X_BUS_WIDTH_16_BITS: |
| 1510 | cctl |= PL080_WIDTH_16BIT << PL080_CONTROL_SWIDTH_SHIFT | |
| 1511 | PL080_WIDTH_16BIT << PL080_CONTROL_DWIDTH_SHIFT; |
| 1512 | break; |
| 1513 | case PL08X_BUS_WIDTH_32_BITS: |
| 1514 | cctl |= PL080_WIDTH_32BIT << PL080_CONTROL_SWIDTH_SHIFT | |
| 1515 | PL080_WIDTH_32BIT << PL080_CONTROL_DWIDTH_SHIFT; |
| 1516 | break; |
| 1517 | } |
| 1518 | |
| 1519 | /* Protection flags */ |
| 1520 | if (pl08x->pd->memcpy_prot_buff) |
| 1521 | cctl |= PL080_CONTROL_PROT_BUFF; |
| 1522 | if (pl08x->pd->memcpy_prot_cache) |
| 1523 | cctl |= PL080_CONTROL_PROT_CACHE; |
| 1524 | |
| 1525 | /* We are the kernel, so we are in privileged mode */ |
| 1526 | cctl |= PL080_CONTROL_PROT_SYS; |
Russell King - ARM Linux | 4983a04 | 2011-01-03 22:39:33 +0000 | [diff] [blame] | 1527 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1528 | /* Both to be incremented or the code will break */ |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 1529 | cctl |= PL080_CONTROL_SRC_INCR | PL080_CONTROL_DST_INCR; |
Russell King - ARM Linux | c7da9a5 | 2011-01-03 22:40:53 +0000 | [diff] [blame] | 1530 | |
Russell King - ARM Linux | c7da9a5 | 2011-01-03 22:40:53 +0000 | [diff] [blame] | 1531 | if (pl08x->vd->dualmaster) |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 1532 | cctl |= pl08x_select_bus(pl08x->mem_buses, |
| 1533 | pl08x->mem_buses); |
| 1534 | |
| 1535 | txd->cctl = cctl; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1536 | |
Russell King | aa4afb7 | 2012-05-26 15:43:00 +0100 | [diff] [blame] | 1537 | ret = pl08x_fill_llis_for_desc(plchan->host, txd); |
| 1538 | if (!ret) { |
| 1539 | pl08x_free_txd(pl08x, txd); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1540 | return NULL; |
Russell King | aa4afb7 | 2012-05-26 15:43:00 +0100 | [diff] [blame] | 1541 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1542 | |
Russell King | 879f127 | 2012-05-26 14:27:40 +0100 | [diff] [blame] | 1543 | return vchan_tx_prep(&plchan->vc, &txd->vd, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1544 | } |
| 1545 | |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 1546 | static struct pl08x_txd *pl08x_init_txd( |
| 1547 | struct dma_chan *chan, |
| 1548 | enum dma_transfer_direction direction, |
| 1549 | dma_addr_t *slave_addr) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1550 | { |
| 1551 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1552 | struct pl08x_driver_data *pl08x = plchan->host; |
| 1553 | struct pl08x_txd *txd; |
Russell King | dc8d5f8 | 2012-05-16 12:20:55 +0100 | [diff] [blame] | 1554 | enum dma_slave_buswidth addr_width; |
Viresh Kumar | 0a23565 | 2011-08-05 15:32:42 +0530 | [diff] [blame] | 1555 | int ret, tmp; |
Russell King | 409ec8d | 2012-05-16 11:08:43 +0100 | [diff] [blame] | 1556 | u8 src_buses, dst_buses; |
Russell King | dc8d5f8 | 2012-05-16 12:20:55 +0100 | [diff] [blame] | 1557 | u32 maxburst, cctl; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1558 | |
Russell King | 879f127 | 2012-05-26 14:27:40 +0100 | [diff] [blame] | 1559 | txd = pl08x_get_txd(plchan); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1560 | if (!txd) { |
| 1561 | dev_err(&pl08x->adev->dev, "%s no txd\n", __func__); |
| 1562 | return NULL; |
| 1563 | } |
| 1564 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1565 | /* |
| 1566 | * Set up addresses, the PrimeCell configured address |
| 1567 | * will take precedence since this may configure the |
| 1568 | * channel target address dynamically at runtime. |
| 1569 | */ |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1570 | if (direction == DMA_MEM_TO_DEV) { |
Russell King | dc8d5f8 | 2012-05-16 12:20:55 +0100 | [diff] [blame] | 1571 | cctl = PL080_CONTROL_SRC_INCR; |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 1572 | *slave_addr = plchan->cfg.dst_addr; |
Russell King | dc8d5f8 | 2012-05-16 12:20:55 +0100 | [diff] [blame] | 1573 | addr_width = plchan->cfg.dst_addr_width; |
| 1574 | maxburst = plchan->cfg.dst_maxburst; |
Russell King | 409ec8d | 2012-05-16 11:08:43 +0100 | [diff] [blame] | 1575 | src_buses = pl08x->mem_buses; |
| 1576 | dst_buses = plchan->cd->periph_buses; |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1577 | } else if (direction == DMA_DEV_TO_MEM) { |
Russell King | dc8d5f8 | 2012-05-16 12:20:55 +0100 | [diff] [blame] | 1578 | cctl = PL080_CONTROL_DST_INCR; |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 1579 | *slave_addr = plchan->cfg.src_addr; |
Russell King | dc8d5f8 | 2012-05-16 12:20:55 +0100 | [diff] [blame] | 1580 | addr_width = plchan->cfg.src_addr_width; |
| 1581 | maxburst = plchan->cfg.src_maxburst; |
Russell King | 409ec8d | 2012-05-16 11:08:43 +0100 | [diff] [blame] | 1582 | src_buses = plchan->cd->periph_buses; |
| 1583 | dst_buses = pl08x->mem_buses; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1584 | } else { |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1585 | pl08x_free_txd(pl08x, txd); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1586 | dev_err(&pl08x->adev->dev, |
| 1587 | "%s direction unsupported\n", __func__); |
| 1588 | return NULL; |
| 1589 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1590 | |
Russell King | dc8d5f8 | 2012-05-16 12:20:55 +0100 | [diff] [blame] | 1591 | cctl |= pl08x_get_cctl(plchan, addr_width, maxburst); |
Russell King | 800d683 | 2012-05-16 11:33:31 +0100 | [diff] [blame] | 1592 | if (cctl == ~0) { |
| 1593 | pl08x_free_txd(pl08x, txd); |
| 1594 | dev_err(&pl08x->adev->dev, |
| 1595 | "DMA slave configuration botched?\n"); |
| 1596 | return NULL; |
| 1597 | } |
| 1598 | |
Russell King | 409ec8d | 2012-05-16 11:08:43 +0100 | [diff] [blame] | 1599 | txd->cctl = cctl | pl08x_select_bus(src_buses, dst_buses); |
| 1600 | |
Russell King | 95442b2 | 2012-05-16 11:05:09 +0100 | [diff] [blame] | 1601 | if (plchan->cfg.device_fc) |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1602 | tmp = (direction == DMA_MEM_TO_DEV) ? PL080_FLOW_MEM2PER_PER : |
Viresh Kumar | 0a23565 | 2011-08-05 15:32:42 +0530 | [diff] [blame] | 1603 | PL080_FLOW_PER2MEM_PER; |
| 1604 | else |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1605 | tmp = (direction == DMA_MEM_TO_DEV) ? PL080_FLOW_MEM2PER : |
Viresh Kumar | 0a23565 | 2011-08-05 15:32:42 +0530 | [diff] [blame] | 1606 | PL080_FLOW_PER2MEM; |
| 1607 | |
| 1608 | txd->ccfg |= tmp << PL080_CONFIG_FLOW_CONTROL_SHIFT; |
| 1609 | |
Russell King | c48d496 | 2012-05-25 11:48:51 +0100 | [diff] [blame] | 1610 | ret = pl08x_request_mux(plchan); |
| 1611 | if (ret < 0) { |
| 1612 | pl08x_free_txd(pl08x, txd); |
| 1613 | dev_dbg(&pl08x->adev->dev, |
| 1614 | "unable to mux for transfer on %s due to platform restrictions\n", |
| 1615 | plchan->name); |
| 1616 | return NULL; |
| 1617 | } |
| 1618 | |
| 1619 | dev_dbg(&pl08x->adev->dev, "allocated DMA request signal %d for xfer on %s\n", |
| 1620 | plchan->signal, plchan->name); |
| 1621 | |
| 1622 | /* Assign the flow control signal to this channel */ |
| 1623 | if (direction == DMA_MEM_TO_DEV) |
| 1624 | txd->ccfg |= plchan->signal << PL080_CONFIG_DST_SEL_SHIFT; |
| 1625 | else |
| 1626 | txd->ccfg |= plchan->signal << PL080_CONFIG_SRC_SEL_SHIFT; |
| 1627 | |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 1628 | return txd; |
| 1629 | } |
| 1630 | |
| 1631 | static int pl08x_tx_add_sg(struct pl08x_txd *txd, |
| 1632 | enum dma_transfer_direction direction, |
| 1633 | dma_addr_t slave_addr, |
| 1634 | dma_addr_t buf_addr, |
| 1635 | unsigned int len) |
| 1636 | { |
| 1637 | struct pl08x_sg *dsg; |
| 1638 | |
| 1639 | dsg = kzalloc(sizeof(struct pl08x_sg), GFP_NOWAIT); |
| 1640 | if (!dsg) |
| 1641 | return -ENOMEM; |
| 1642 | |
| 1643 | list_add_tail(&dsg->node, &txd->dsg_list); |
| 1644 | |
| 1645 | dsg->len = len; |
| 1646 | if (direction == DMA_MEM_TO_DEV) { |
| 1647 | dsg->src_addr = buf_addr; |
| 1648 | dsg->dst_addr = slave_addr; |
| 1649 | } else { |
| 1650 | dsg->src_addr = slave_addr; |
| 1651 | dsg->dst_addr = buf_addr; |
| 1652 | } |
| 1653 | |
| 1654 | return 0; |
| 1655 | } |
| 1656 | |
| 1657 | static struct dma_async_tx_descriptor *pl08x_prep_slave_sg( |
| 1658 | struct dma_chan *chan, struct scatterlist *sgl, |
| 1659 | unsigned int sg_len, enum dma_transfer_direction direction, |
| 1660 | unsigned long flags, void *context) |
| 1661 | { |
| 1662 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1663 | struct pl08x_driver_data *pl08x = plchan->host; |
| 1664 | struct pl08x_txd *txd; |
| 1665 | struct scatterlist *sg; |
| 1666 | int ret, tmp; |
| 1667 | dma_addr_t slave_addr; |
| 1668 | |
| 1669 | dev_dbg(&pl08x->adev->dev, "%s prepare transaction of %d bytes from %s\n", |
| 1670 | __func__, sg_dma_len(sgl), plchan->name); |
| 1671 | |
| 1672 | txd = pl08x_init_txd(chan, direction, &slave_addr); |
| 1673 | if (!txd) |
| 1674 | return NULL; |
| 1675 | |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1676 | for_each_sg(sgl, sg, sg_len, tmp) { |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 1677 | ret = pl08x_tx_add_sg(txd, direction, slave_addr, |
| 1678 | sg_dma_address(sg), |
| 1679 | sg_dma_len(sg)); |
| 1680 | if (ret) { |
Russell King | c48d496 | 2012-05-25 11:48:51 +0100 | [diff] [blame] | 1681 | pl08x_release_mux(plchan); |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1682 | pl08x_free_txd(pl08x, txd); |
| 1683 | dev_err(&pl08x->adev->dev, "%s no mem for pl080 sg\n", |
| 1684 | __func__); |
| 1685 | return NULL; |
| 1686 | } |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 1687 | } |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1688 | |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 1689 | ret = pl08x_fill_llis_for_desc(plchan->host, txd); |
| 1690 | if (!ret) { |
| 1691 | pl08x_release_mux(plchan); |
| 1692 | pl08x_free_txd(pl08x, txd); |
| 1693 | return NULL; |
| 1694 | } |
| 1695 | |
| 1696 | return vchan_tx_prep(&plchan->vc, &txd->vd, flags); |
| 1697 | } |
| 1698 | |
| 1699 | static struct dma_async_tx_descriptor *pl08x_prep_dma_cyclic( |
| 1700 | struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, |
| 1701 | size_t period_len, enum dma_transfer_direction direction, |
Laurent Pinchart | 31c1e5a | 2014-08-01 12:20:10 +0200 | [diff] [blame] | 1702 | unsigned long flags) |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 1703 | { |
| 1704 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1705 | struct pl08x_driver_data *pl08x = plchan->host; |
| 1706 | struct pl08x_txd *txd; |
| 1707 | int ret, tmp; |
| 1708 | dma_addr_t slave_addr; |
| 1709 | |
| 1710 | dev_dbg(&pl08x->adev->dev, |
Mark Brown | 6fc8ae7 | 2014-08-01 18:09:48 +0100 | [diff] [blame] | 1711 | "%s prepare cyclic transaction of %zd/%zd bytes %s %s\n", |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 1712 | __func__, period_len, buf_len, |
| 1713 | direction == DMA_MEM_TO_DEV ? "to" : "from", |
| 1714 | plchan->name); |
| 1715 | |
| 1716 | txd = pl08x_init_txd(chan, direction, &slave_addr); |
| 1717 | if (!txd) |
| 1718 | return NULL; |
| 1719 | |
| 1720 | txd->cyclic = true; |
| 1721 | txd->cctl |= PL080_CONTROL_TC_IRQ_EN; |
| 1722 | for (tmp = 0; tmp < buf_len; tmp += period_len) { |
| 1723 | ret = pl08x_tx_add_sg(txd, direction, slave_addr, |
| 1724 | buf_addr + tmp, period_len); |
| 1725 | if (ret) { |
| 1726 | pl08x_release_mux(plchan); |
| 1727 | pl08x_free_txd(pl08x, txd); |
| 1728 | return NULL; |
Viresh Kumar | b7f69d9 | 2011-08-05 15:32:43 +0530 | [diff] [blame] | 1729 | } |
| 1730 | } |
| 1731 | |
Russell King | aa4afb7 | 2012-05-26 15:43:00 +0100 | [diff] [blame] | 1732 | ret = pl08x_fill_llis_for_desc(plchan->host, txd); |
| 1733 | if (!ret) { |
| 1734 | pl08x_release_mux(plchan); |
| 1735 | pl08x_free_txd(pl08x, txd); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1736 | return NULL; |
Russell King | aa4afb7 | 2012-05-26 15:43:00 +0100 | [diff] [blame] | 1737 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1738 | |
Russell King | 879f127 | 2012-05-26 14:27:40 +0100 | [diff] [blame] | 1739 | return vchan_tx_prep(&plchan->vc, &txd->vd, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1740 | } |
| 1741 | |
Maxime Ripard | bcd1b0b | 2014-11-17 14:42:05 +0100 | [diff] [blame] | 1742 | static int pl08x_config(struct dma_chan *chan, |
| 1743 | struct dma_slave_config *config) |
| 1744 | { |
| 1745 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1746 | struct pl08x_driver_data *pl08x = plchan->host; |
| 1747 | |
| 1748 | if (!plchan->slave) |
| 1749 | return -EINVAL; |
| 1750 | |
| 1751 | /* Reject definitely invalid configurations */ |
| 1752 | if (config->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES || |
| 1753 | config->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES) |
| 1754 | return -EINVAL; |
| 1755 | |
| 1756 | if (config->device_fc && pl08x->vd->pl080s) { |
| 1757 | dev_err(&pl08x->adev->dev, |
| 1758 | "%s: PL080S does not support peripheral flow control\n", |
| 1759 | __func__); |
| 1760 | return -EINVAL; |
| 1761 | } |
| 1762 | |
| 1763 | plchan->cfg = *config; |
| 1764 | |
| 1765 | return 0; |
| 1766 | } |
| 1767 | |
| 1768 | static int pl08x_terminate_all(struct dma_chan *chan) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1769 | { |
| 1770 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1771 | struct pl08x_driver_data *pl08x = plchan->host; |
| 1772 | unsigned long flags; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1773 | |
Maxime Ripard | bcd1b0b | 2014-11-17 14:42:05 +0100 | [diff] [blame] | 1774 | spin_lock_irqsave(&plchan->vc.lock, flags); |
| 1775 | if (!plchan->phychan && !plchan->at) { |
| 1776 | spin_unlock_irqrestore(&plchan->vc.lock, flags); |
| 1777 | return 0; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1778 | } |
| 1779 | |
Maxime Ripard | bcd1b0b | 2014-11-17 14:42:05 +0100 | [diff] [blame] | 1780 | plchan->state = PL08X_CHAN_IDLE; |
| 1781 | |
| 1782 | if (plchan->phychan) { |
| 1783 | /* |
| 1784 | * Mark physical channel as free and free any slave |
| 1785 | * signal |
| 1786 | */ |
| 1787 | pl08x_phy_free(plchan); |
| 1788 | } |
| 1789 | /* Dequeue jobs and free LLIs */ |
| 1790 | if (plchan->at) { |
| 1791 | pl08x_desc_free(&plchan->at->vd); |
| 1792 | plchan->at = NULL; |
| 1793 | } |
| 1794 | /* Dequeue jobs not yet fired as well */ |
| 1795 | pl08x_free_txd_list(pl08x, plchan); |
| 1796 | |
| 1797 | spin_unlock_irqrestore(&plchan->vc.lock, flags); |
| 1798 | |
| 1799 | return 0; |
| 1800 | } |
| 1801 | |
| 1802 | static int pl08x_pause(struct dma_chan *chan) |
| 1803 | { |
| 1804 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1805 | unsigned long flags; |
| 1806 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1807 | /* |
| 1808 | * Anything succeeds on channels with no physical allocation and |
| 1809 | * no queued transfers. |
| 1810 | */ |
Russell King | 083be28 | 2012-05-26 14:09:53 +0100 | [diff] [blame] | 1811 | spin_lock_irqsave(&plchan->vc.lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1812 | if (!plchan->phychan && !plchan->at) { |
Russell King | 083be28 | 2012-05-26 14:09:53 +0100 | [diff] [blame] | 1813 | spin_unlock_irqrestore(&plchan->vc.lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1814 | return 0; |
| 1815 | } |
| 1816 | |
Maxime Ripard | bcd1b0b | 2014-11-17 14:42:05 +0100 | [diff] [blame] | 1817 | pl08x_pause_phy_chan(plchan->phychan); |
| 1818 | plchan->state = PL08X_CHAN_PAUSED; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1819 | |
Russell King | 083be28 | 2012-05-26 14:09:53 +0100 | [diff] [blame] | 1820 | spin_unlock_irqrestore(&plchan->vc.lock, flags); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1821 | |
Maxime Ripard | bcd1b0b | 2014-11-17 14:42:05 +0100 | [diff] [blame] | 1822 | return 0; |
| 1823 | } |
| 1824 | |
| 1825 | static int pl08x_resume(struct dma_chan *chan) |
| 1826 | { |
| 1827 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1828 | unsigned long flags; |
| 1829 | |
| 1830 | /* |
| 1831 | * Anything succeeds on channels with no physical allocation and |
| 1832 | * no queued transfers. |
| 1833 | */ |
| 1834 | spin_lock_irqsave(&plchan->vc.lock, flags); |
| 1835 | if (!plchan->phychan && !plchan->at) { |
| 1836 | spin_unlock_irqrestore(&plchan->vc.lock, flags); |
| 1837 | return 0; |
| 1838 | } |
| 1839 | |
| 1840 | pl08x_resume_phy_chan(plchan->phychan); |
| 1841 | plchan->state = PL08X_CHAN_RUNNING; |
| 1842 | |
| 1843 | spin_unlock_irqrestore(&plchan->vc.lock, flags); |
| 1844 | |
| 1845 | return 0; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | bool pl08x_filter_id(struct dma_chan *chan, void *chan_id) |
| 1849 | { |
Russell King - ARM Linux | 7703eac | 2011-08-31 09:34:35 +0100 | [diff] [blame] | 1850 | struct pl08x_dma_chan *plchan; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1851 | char *name = chan_id; |
| 1852 | |
Russell King - ARM Linux | 7703eac | 2011-08-31 09:34:35 +0100 | [diff] [blame] | 1853 | /* Reject channels for devices not bound to this driver */ |
| 1854 | if (chan->device->dev->driver != &pl08x_amba_driver.drv) |
| 1855 | return false; |
| 1856 | |
| 1857 | plchan = to_pl08x_chan(chan); |
| 1858 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1859 | /* Check that the channel is not taken! */ |
| 1860 | if (!strcmp(plchan->name, name)) |
| 1861 | return true; |
| 1862 | |
| 1863 | return false; |
| 1864 | } |
Sachin Kamat | 6d05c9f | 2014-01-23 16:10:07 +0530 | [diff] [blame] | 1865 | EXPORT_SYMBOL_GPL(pl08x_filter_id); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1866 | |
Sylwester Nawrocki | da6f8ca | 2016-11-10 16:17:49 +0100 | [diff] [blame] | 1867 | static bool pl08x_filter_fn(struct dma_chan *chan, void *chan_id) |
| 1868 | { |
| 1869 | struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); |
| 1870 | |
| 1871 | return plchan->cd == chan_id; |
| 1872 | } |
| 1873 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1874 | /* |
| 1875 | * Just check that the device is there and active |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1876 | * TODO: turn this bit on/off depending on the number of physical channels |
| 1877 | * actually used, if it is zero... well shut it off. That will save some |
| 1878 | * power. Cut the clock at the same time. |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1879 | */ |
| 1880 | static void pl08x_ensure_on(struct pl08x_driver_data *pl08x) |
| 1881 | { |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 1882 | /* The Nomadik variant does not have the config register */ |
| 1883 | if (pl08x->vd->nomadik) |
| 1884 | return; |
Viresh Kumar | 48a59ef | 2011-08-05 15:32:34 +0530 | [diff] [blame] | 1885 | writel(PL080_CONFIG_ENABLE, pl08x->base + PL080_CONFIG); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1886 | } |
| 1887 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1888 | static irqreturn_t pl08x_irq(int irq, void *dev) |
| 1889 | { |
| 1890 | struct pl08x_driver_data *pl08x = dev; |
Viresh Kumar | 28da283 | 2011-08-05 15:32:36 +0530 | [diff] [blame] | 1891 | u32 mask = 0, err, tc, i; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1892 | |
Viresh Kumar | 28da283 | 2011-08-05 15:32:36 +0530 | [diff] [blame] | 1893 | /* check & clear - ERR & TC interrupts */ |
| 1894 | err = readl(pl08x->base + PL080_ERR_STATUS); |
| 1895 | if (err) { |
| 1896 | dev_err(&pl08x->adev->dev, "%s error interrupt, register value 0x%08x\n", |
| 1897 | __func__, err); |
| 1898 | writel(err, pl08x->base + PL080_ERR_CLEAR); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1899 | } |
Linus Walleij | d29bf01 | 2012-04-09 22:53:21 +0200 | [diff] [blame] | 1900 | tc = readl(pl08x->base + PL080_TC_STATUS); |
Viresh Kumar | 28da283 | 2011-08-05 15:32:36 +0530 | [diff] [blame] | 1901 | if (tc) |
| 1902 | writel(tc, pl08x->base + PL080_TC_CLEAR); |
| 1903 | |
| 1904 | if (!err && !tc) |
| 1905 | return IRQ_NONE; |
| 1906 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1907 | for (i = 0; i < pl08x->vd->channels; i++) { |
Linus Walleij | ded091f | 2017-04-02 16:50:53 +0200 | [diff] [blame] | 1908 | if ((BIT(i) & err) || (BIT(i) & tc)) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1909 | /* Locate physical channel */ |
| 1910 | struct pl08x_phy_chan *phychan = &pl08x->phy_chans[i]; |
| 1911 | struct pl08x_dma_chan *plchan = phychan->serving; |
Russell King | a936e79 | 2012-05-25 10:51:19 +0100 | [diff] [blame] | 1912 | struct pl08x_txd *tx; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1913 | |
Viresh Kumar | 28da283 | 2011-08-05 15:32:36 +0530 | [diff] [blame] | 1914 | if (!plchan) { |
| 1915 | dev_err(&pl08x->adev->dev, |
| 1916 | "%s Error TC interrupt on unused channel: 0x%08x\n", |
| 1917 | __func__, i); |
| 1918 | continue; |
| 1919 | } |
| 1920 | |
Russell King | 083be28 | 2012-05-26 14:09:53 +0100 | [diff] [blame] | 1921 | spin_lock(&plchan->vc.lock); |
Russell King | a936e79 | 2012-05-25 10:51:19 +0100 | [diff] [blame] | 1922 | tx = plchan->at; |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 1923 | if (tx && tx->cyclic) { |
| 1924 | vchan_cyclic_callback(&tx->vd); |
| 1925 | } else if (tx) { |
Russell King | a936e79 | 2012-05-25 10:51:19 +0100 | [diff] [blame] | 1926 | plchan->at = NULL; |
Russell King | c48d496 | 2012-05-25 11:48:51 +0100 | [diff] [blame] | 1927 | /* |
| 1928 | * This descriptor is done, release its mux |
| 1929 | * reservation. |
| 1930 | */ |
| 1931 | pl08x_release_mux(plchan); |
Russell King | 1853613 | 2012-05-26 14:42:23 +0100 | [diff] [blame] | 1932 | tx->done = true; |
| 1933 | vchan_cookie_complete(&tx->vd); |
Russell King | c33b644 | 2012-05-25 15:41:13 +0100 | [diff] [blame] | 1934 | |
Russell King | a5a488d | 2012-05-26 13:54:15 +0100 | [diff] [blame] | 1935 | /* |
| 1936 | * And start the next descriptor (if any), |
| 1937 | * otherwise free this channel. |
| 1938 | */ |
Russell King | 879f127 | 2012-05-26 14:27:40 +0100 | [diff] [blame] | 1939 | if (vchan_next_desc(&plchan->vc)) |
Russell King | c33b644 | 2012-05-25 15:41:13 +0100 | [diff] [blame] | 1940 | pl08x_start_next_txd(plchan); |
Russell King | a5a488d | 2012-05-26 13:54:15 +0100 | [diff] [blame] | 1941 | else |
| 1942 | pl08x_phy_free(plchan); |
Russell King | a936e79 | 2012-05-25 10:51:19 +0100 | [diff] [blame] | 1943 | } |
Russell King | 083be28 | 2012-05-26 14:09:53 +0100 | [diff] [blame] | 1944 | spin_unlock(&plchan->vc.lock); |
Russell King | a936e79 | 2012-05-25 10:51:19 +0100 | [diff] [blame] | 1945 | |
Linus Walleij | ded091f | 2017-04-02 16:50:53 +0200 | [diff] [blame] | 1946 | mask |= BIT(i); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1947 | } |
| 1948 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1949 | |
| 1950 | return mask ? IRQ_HANDLED : IRQ_NONE; |
| 1951 | } |
| 1952 | |
Russell King - ARM Linux | 121c847 | 2011-07-21 17:13:48 +0100 | [diff] [blame] | 1953 | static void pl08x_dma_slave_init(struct pl08x_dma_chan *chan) |
| 1954 | { |
Russell King - ARM Linux | 121c847 | 2011-07-21 17:13:48 +0100 | [diff] [blame] | 1955 | chan->slave = true; |
| 1956 | chan->name = chan->cd->bus_id; |
Russell King | ed91c13 | 2012-05-16 11:02:40 +0100 | [diff] [blame] | 1957 | chan->cfg.src_addr = chan->cd->addr; |
| 1958 | chan->cfg.dst_addr = chan->cd->addr; |
Russell King - ARM Linux | 121c847 | 2011-07-21 17:13:48 +0100 | [diff] [blame] | 1959 | } |
| 1960 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1961 | /* |
| 1962 | * Initialise the DMAC memcpy/slave channels. |
| 1963 | * Make a local wrapper to hold required data |
| 1964 | */ |
| 1965 | static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x, |
Viresh Kumar | 3e27ee8 | 2011-08-05 15:32:27 +0530 | [diff] [blame] | 1966 | struct dma_device *dmadev, unsigned int channels, bool slave) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1967 | { |
| 1968 | struct pl08x_dma_chan *chan; |
| 1969 | int i; |
| 1970 | |
| 1971 | INIT_LIST_HEAD(&dmadev->channels); |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 1972 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1973 | /* |
| 1974 | * Register as many many memcpy as we have physical channels, |
| 1975 | * we won't always be able to use all but the code will have |
| 1976 | * to cope with that situation. |
| 1977 | */ |
| 1978 | for (i = 0; i < channels; i++) { |
Viresh Kumar | b201c11 | 2011-08-05 15:32:29 +0530 | [diff] [blame] | 1979 | chan = kzalloc(sizeof(*chan), GFP_KERNEL); |
Peter Griffin | aef94fe | 2016-06-07 18:38:41 +0100 | [diff] [blame] | 1980 | if (!chan) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1981 | return -ENOMEM; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1982 | |
| 1983 | chan->host = pl08x; |
| 1984 | chan->state = PL08X_CHAN_IDLE; |
Russell King | ad0de2a | 2012-05-25 11:15:15 +0100 | [diff] [blame] | 1985 | chan->signal = -1; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1986 | |
| 1987 | if (slave) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1988 | chan->cd = &pl08x->pd->slave_channels[i]; |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 1989 | /* |
| 1990 | * Some implementations have muxed signals, whereas some |
| 1991 | * use a mux in front of the signals and need dynamic |
| 1992 | * assignment of signals. |
| 1993 | */ |
| 1994 | chan->signal = i; |
Russell King - ARM Linux | 121c847 | 2011-07-21 17:13:48 +0100 | [diff] [blame] | 1995 | pl08x_dma_slave_init(chan); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 1996 | } else { |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 1997 | chan->cd = kzalloc(sizeof(*chan->cd), GFP_KERNEL); |
| 1998 | if (!chan->cd) { |
| 1999 | kfree(chan); |
| 2000 | return -ENOMEM; |
| 2001 | } |
| 2002 | chan->cd->bus_id = "memcpy"; |
| 2003 | chan->cd->periph_buses = pl08x->pd->mem_buses; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2004 | chan->name = kasprintf(GFP_KERNEL, "memcpy%d", i); |
| 2005 | if (!chan->name) { |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2006 | kfree(chan->cd); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2007 | kfree(chan); |
| 2008 | return -ENOMEM; |
| 2009 | } |
| 2010 | } |
Viresh Kumar | 175a5e6 | 2011-08-05 15:32:32 +0530 | [diff] [blame] | 2011 | dev_dbg(&pl08x->adev->dev, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2012 | "initialize virtual channel \"%s\"\n", |
| 2013 | chan->name); |
| 2014 | |
Russell King | 1853613 | 2012-05-26 14:42:23 +0100 | [diff] [blame] | 2015 | chan->vc.desc_free = pl08x_desc_free; |
Russell King | 083be28 | 2012-05-26 14:09:53 +0100 | [diff] [blame] | 2016 | vchan_init(&chan->vc, dmadev); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2017 | } |
| 2018 | dev_info(&pl08x->adev->dev, "initialized %d virtual %s channels\n", |
| 2019 | i, slave ? "slave" : "memcpy"); |
| 2020 | return i; |
| 2021 | } |
| 2022 | |
| 2023 | static void pl08x_free_virtual_channels(struct dma_device *dmadev) |
| 2024 | { |
| 2025 | struct pl08x_dma_chan *chan = NULL; |
| 2026 | struct pl08x_dma_chan *next; |
| 2027 | |
| 2028 | list_for_each_entry_safe(chan, |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 2029 | next, &dmadev->channels, vc.chan.device_node) { |
| 2030 | list_del(&chan->vc.chan.device_node); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2031 | kfree(chan); |
| 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | #ifdef CONFIG_DEBUG_FS |
| 2036 | static const char *pl08x_state_str(enum pl08x_dma_chan_state state) |
| 2037 | { |
| 2038 | switch (state) { |
| 2039 | case PL08X_CHAN_IDLE: |
| 2040 | return "idle"; |
| 2041 | case PL08X_CHAN_RUNNING: |
| 2042 | return "running"; |
| 2043 | case PL08X_CHAN_PAUSED: |
| 2044 | return "paused"; |
| 2045 | case PL08X_CHAN_WAITING: |
| 2046 | return "waiting"; |
| 2047 | default: |
| 2048 | break; |
| 2049 | } |
| 2050 | return "UNKNOWN STATE"; |
| 2051 | } |
| 2052 | |
| 2053 | static int pl08x_debugfs_show(struct seq_file *s, void *data) |
| 2054 | { |
| 2055 | struct pl08x_driver_data *pl08x = s->private; |
| 2056 | struct pl08x_dma_chan *chan; |
| 2057 | struct pl08x_phy_chan *ch; |
| 2058 | unsigned long flags; |
| 2059 | int i; |
| 2060 | |
| 2061 | seq_printf(s, "PL08x physical channels:\n"); |
| 2062 | seq_printf(s, "CHANNEL:\tUSER:\n"); |
| 2063 | seq_printf(s, "--------\t-----\n"); |
| 2064 | for (i = 0; i < pl08x->vd->channels; i++) { |
| 2065 | struct pl08x_dma_chan *virt_chan; |
| 2066 | |
| 2067 | ch = &pl08x->phy_chans[i]; |
| 2068 | |
| 2069 | spin_lock_irqsave(&ch->lock, flags); |
| 2070 | virt_chan = ch->serving; |
| 2071 | |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 2072 | seq_printf(s, "%d\t\t%s%s\n", |
| 2073 | ch->id, |
| 2074 | virt_chan ? virt_chan->name : "(none)", |
| 2075 | ch->locked ? " LOCKED" : ""); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2076 | |
| 2077 | spin_unlock_irqrestore(&ch->lock, flags); |
| 2078 | } |
| 2079 | |
| 2080 | seq_printf(s, "\nPL08x virtual memcpy channels:\n"); |
| 2081 | seq_printf(s, "CHANNEL:\tSTATE:\n"); |
| 2082 | seq_printf(s, "--------\t------\n"); |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 2083 | list_for_each_entry(chan, &pl08x->memcpy.channels, vc.chan.device_node) { |
Russell King - ARM Linux | 3e2a037 | 2011-01-03 22:32:46 +0000 | [diff] [blame] | 2084 | seq_printf(s, "%s\t\t%s\n", chan->name, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2085 | pl08x_state_str(chan->state)); |
| 2086 | } |
| 2087 | |
| 2088 | seq_printf(s, "\nPL08x virtual slave channels:\n"); |
| 2089 | seq_printf(s, "CHANNEL:\tSTATE:\n"); |
| 2090 | seq_printf(s, "--------\t------\n"); |
Russell King | 01d8dc6 | 2012-05-26 14:04:29 +0100 | [diff] [blame] | 2091 | list_for_each_entry(chan, &pl08x->slave.channels, vc.chan.device_node) { |
Russell King - ARM Linux | 3e2a037 | 2011-01-03 22:32:46 +0000 | [diff] [blame] | 2092 | seq_printf(s, "%s\t\t%s\n", chan->name, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2093 | pl08x_state_str(chan->state)); |
| 2094 | } |
| 2095 | |
| 2096 | return 0; |
| 2097 | } |
| 2098 | |
| 2099 | static int pl08x_debugfs_open(struct inode *inode, struct file *file) |
| 2100 | { |
| 2101 | return single_open(file, pl08x_debugfs_show, inode->i_private); |
| 2102 | } |
| 2103 | |
| 2104 | static const struct file_operations pl08x_debugfs_operations = { |
| 2105 | .open = pl08x_debugfs_open, |
| 2106 | .read = seq_read, |
| 2107 | .llseek = seq_lseek, |
| 2108 | .release = single_release, |
| 2109 | }; |
| 2110 | |
| 2111 | static void init_pl08x_debugfs(struct pl08x_driver_data *pl08x) |
| 2112 | { |
| 2113 | /* Expose a simple debugfs interface to view all clocks */ |
Viresh Kumar | 3e27ee8 | 2011-08-05 15:32:27 +0530 | [diff] [blame] | 2114 | (void) debugfs_create_file(dev_name(&pl08x->adev->dev), |
| 2115 | S_IFREG | S_IRUGO, NULL, pl08x, |
| 2116 | &pl08x_debugfs_operations); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | #else |
| 2120 | static inline void init_pl08x_debugfs(struct pl08x_driver_data *pl08x) |
| 2121 | { |
| 2122 | } |
| 2123 | #endif |
| 2124 | |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2125 | #ifdef CONFIG_OF |
| 2126 | static struct dma_chan *pl08x_find_chan_id(struct pl08x_driver_data *pl08x, |
| 2127 | u32 id) |
| 2128 | { |
| 2129 | struct pl08x_dma_chan *chan; |
| 2130 | |
| 2131 | list_for_each_entry(chan, &pl08x->slave.channels, vc.chan.device_node) { |
| 2132 | if (chan->signal == id) |
| 2133 | return &chan->vc.chan; |
| 2134 | } |
| 2135 | |
| 2136 | return NULL; |
| 2137 | } |
| 2138 | |
| 2139 | static struct dma_chan *pl08x_of_xlate(struct of_phandle_args *dma_spec, |
| 2140 | struct of_dma *ofdma) |
| 2141 | { |
| 2142 | struct pl08x_driver_data *pl08x = ofdma->of_dma_data; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2143 | struct dma_chan *dma_chan; |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2144 | struct pl08x_dma_chan *plchan; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2145 | |
| 2146 | if (!pl08x) |
| 2147 | return NULL; |
| 2148 | |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2149 | if (dma_spec->args_count != 2) { |
| 2150 | dev_err(&pl08x->adev->dev, |
| 2151 | "DMA channel translation requires two cells\n"); |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2152 | return NULL; |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2153 | } |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2154 | |
| 2155 | dma_chan = pl08x_find_chan_id(pl08x, dma_spec->args[0]); |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2156 | if (!dma_chan) { |
| 2157 | dev_err(&pl08x->adev->dev, |
| 2158 | "DMA slave channel not found\n"); |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2159 | return NULL; |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2160 | } |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2161 | |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2162 | plchan = to_pl08x_chan(dma_chan); |
| 2163 | dev_dbg(&pl08x->adev->dev, |
| 2164 | "translated channel for signal %d\n", |
| 2165 | dma_spec->args[0]); |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2166 | |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2167 | /* Augment channel data for applicable AHB buses */ |
| 2168 | plchan->cd->periph_buses = dma_spec->args[1]; |
| 2169 | return dma_get_slave_channel(dma_chan); |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | static int pl08x_of_probe(struct amba_device *adev, |
| 2173 | struct pl08x_driver_data *pl08x, |
| 2174 | struct device_node *np) |
| 2175 | { |
| 2176 | struct pl08x_platform_data *pd; |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2177 | struct pl08x_channel_data *chanp = NULL; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2178 | u32 val; |
| 2179 | int ret; |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2180 | int i; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2181 | |
| 2182 | pd = devm_kzalloc(&adev->dev, sizeof(*pd), GFP_KERNEL); |
| 2183 | if (!pd) |
| 2184 | return -ENOMEM; |
| 2185 | |
| 2186 | /* Eligible bus masters for fetching LLIs */ |
| 2187 | if (of_property_read_bool(np, "lli-bus-interface-ahb1")) |
| 2188 | pd->lli_buses |= PL08X_AHB1; |
| 2189 | if (of_property_read_bool(np, "lli-bus-interface-ahb2")) |
| 2190 | pd->lli_buses |= PL08X_AHB2; |
| 2191 | if (!pd->lli_buses) { |
| 2192 | dev_info(&adev->dev, "no bus masters for LLIs stated, assume all\n"); |
| 2193 | pd->lli_buses |= PL08X_AHB1 | PL08X_AHB2; |
| 2194 | } |
| 2195 | |
| 2196 | /* Eligible bus masters for memory access */ |
| 2197 | if (of_property_read_bool(np, "mem-bus-interface-ahb1")) |
| 2198 | pd->mem_buses |= PL08X_AHB1; |
| 2199 | if (of_property_read_bool(np, "mem-bus-interface-ahb2")) |
| 2200 | pd->mem_buses |= PL08X_AHB2; |
| 2201 | if (!pd->mem_buses) { |
| 2202 | dev_info(&adev->dev, "no bus masters for memory stated, assume all\n"); |
| 2203 | pd->mem_buses |= PL08X_AHB1 | PL08X_AHB2; |
| 2204 | } |
| 2205 | |
| 2206 | /* Parse the memcpy channel properties */ |
| 2207 | ret = of_property_read_u32(np, "memcpy-burst-size", &val); |
| 2208 | if (ret) { |
| 2209 | dev_info(&adev->dev, "no memcpy burst size specified, using 1 byte\n"); |
| 2210 | val = 1; |
| 2211 | } |
| 2212 | switch (val) { |
| 2213 | default: |
| 2214 | dev_err(&adev->dev, "illegal burst size for memcpy, set to 1\n"); |
| 2215 | /* Fall through */ |
| 2216 | case 1: |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2217 | pd->memcpy_burst_size = PL08X_BURST_SZ_1; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2218 | break; |
| 2219 | case 4: |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2220 | pd->memcpy_burst_size = PL08X_BURST_SZ_4; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2221 | break; |
| 2222 | case 8: |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2223 | pd->memcpy_burst_size = PL08X_BURST_SZ_8; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2224 | break; |
| 2225 | case 16: |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2226 | pd->memcpy_burst_size = PL08X_BURST_SZ_16; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2227 | break; |
| 2228 | case 32: |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2229 | pd->memcpy_burst_size = PL08X_BURST_SZ_32; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2230 | break; |
| 2231 | case 64: |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2232 | pd->memcpy_burst_size = PL08X_BURST_SZ_64; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2233 | break; |
| 2234 | case 128: |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2235 | pd->memcpy_burst_size = PL08X_BURST_SZ_128; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2236 | break; |
| 2237 | case 256: |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2238 | pd->memcpy_burst_size = PL08X_BURST_SZ_256; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2239 | break; |
| 2240 | } |
| 2241 | |
| 2242 | ret = of_property_read_u32(np, "memcpy-bus-width", &val); |
| 2243 | if (ret) { |
| 2244 | dev_info(&adev->dev, "no memcpy bus width specified, using 8 bits\n"); |
| 2245 | val = 8; |
| 2246 | } |
| 2247 | switch (val) { |
| 2248 | default: |
| 2249 | dev_err(&adev->dev, "illegal bus width for memcpy, set to 8 bits\n"); |
| 2250 | /* Fall through */ |
| 2251 | case 8: |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2252 | pd->memcpy_bus_width = PL08X_BUS_WIDTH_8_BITS; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2253 | break; |
| 2254 | case 16: |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2255 | pd->memcpy_bus_width = PL08X_BUS_WIDTH_16_BITS; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2256 | break; |
| 2257 | case 32: |
Linus Walleij | 4166a56 | 2017-05-20 23:42:50 +0200 | [diff] [blame] | 2258 | pd->memcpy_bus_width = PL08X_BUS_WIDTH_32_BITS; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2259 | break; |
| 2260 | } |
| 2261 | |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2262 | /* |
| 2263 | * Allocate channel data for all possible slave channels (one |
| 2264 | * for each possible signal), channels will then be allocated |
| 2265 | * for a device and have it's AHB interfaces set up at |
| 2266 | * translation time. |
| 2267 | */ |
| 2268 | chanp = devm_kcalloc(&adev->dev, |
| 2269 | pl08x->vd->signals, |
| 2270 | sizeof(struct pl08x_channel_data), |
| 2271 | GFP_KERNEL); |
| 2272 | if (!chanp) |
| 2273 | return -ENOMEM; |
| 2274 | |
| 2275 | pd->slave_channels = chanp; |
| 2276 | for (i = 0; i < pl08x->vd->signals; i++) { |
| 2277 | /* chanp->periph_buses will be assigned at translation */ |
| 2278 | chanp->bus_id = kasprintf(GFP_KERNEL, "slave%d", i); |
| 2279 | chanp++; |
| 2280 | } |
| 2281 | pd->num_slave_channels = pl08x->vd->signals; |
| 2282 | |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2283 | pl08x->pd = pd; |
| 2284 | |
| 2285 | return of_dma_controller_register(adev->dev.of_node, pl08x_of_xlate, |
| 2286 | pl08x); |
| 2287 | } |
| 2288 | #else |
| 2289 | static inline int pl08x_of_probe(struct amba_device *adev, |
| 2290 | struct pl08x_driver_data *pl08x, |
| 2291 | struct device_node *np) |
| 2292 | { |
| 2293 | return -EINVAL; |
| 2294 | } |
| 2295 | #endif |
| 2296 | |
Russell King | aa25afa | 2011-02-19 15:55:00 +0000 | [diff] [blame] | 2297 | static int pl08x_probe(struct amba_device *adev, const struct amba_id *id) |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2298 | { |
| 2299 | struct pl08x_driver_data *pl08x; |
Russell King - ARM Linux | f96ca9ec | 2011-01-03 22:35:08 +0000 | [diff] [blame] | 2300 | const struct vendor_data *vd = id->data; |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2301 | struct device_node *np = adev->dev.of_node; |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 2302 | u32 tsfr_size; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2303 | int ret = 0; |
| 2304 | int i; |
| 2305 | |
| 2306 | ret = amba_request_regions(adev, NULL); |
| 2307 | if (ret) |
| 2308 | return ret; |
| 2309 | |
Russell King | de1a241 | 2013-06-27 10:29:32 +0100 | [diff] [blame] | 2310 | /* Ensure that we can do DMA */ |
| 2311 | ret = dma_set_mask_and_coherent(&adev->dev, DMA_BIT_MASK(32)); |
| 2312 | if (ret) |
| 2313 | goto out_no_pl08x; |
| 2314 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2315 | /* Create the driver state holder */ |
Viresh Kumar | b201c11 | 2011-08-05 15:32:29 +0530 | [diff] [blame] | 2316 | pl08x = kzalloc(sizeof(*pl08x), GFP_KERNEL); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2317 | if (!pl08x) { |
| 2318 | ret = -ENOMEM; |
| 2319 | goto out_no_pl08x; |
| 2320 | } |
| 2321 | |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2322 | /* Assign useful pointers to the driver state */ |
| 2323 | pl08x->adev = adev; |
| 2324 | pl08x->vd = vd; |
| 2325 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2326 | /* Initialize memcpy engine */ |
| 2327 | dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask); |
| 2328 | pl08x->memcpy.dev = &adev->dev; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2329 | pl08x->memcpy.device_free_chan_resources = pl08x_free_chan_resources; |
| 2330 | pl08x->memcpy.device_prep_dma_memcpy = pl08x_prep_dma_memcpy; |
| 2331 | pl08x->memcpy.device_prep_dma_interrupt = pl08x_prep_dma_interrupt; |
| 2332 | pl08x->memcpy.device_tx_status = pl08x_dma_tx_status; |
| 2333 | pl08x->memcpy.device_issue_pending = pl08x_issue_pending; |
Maxime Ripard | bcd1b0b | 2014-11-17 14:42:05 +0100 | [diff] [blame] | 2334 | pl08x->memcpy.device_config = pl08x_config; |
| 2335 | pl08x->memcpy.device_pause = pl08x_pause; |
| 2336 | pl08x->memcpy.device_resume = pl08x_resume; |
| 2337 | pl08x->memcpy.device_terminate_all = pl08x_terminate_all; |
Mark Brown | ea524c7 | 2015-03-17 23:25:36 +0000 | [diff] [blame] | 2338 | pl08x->memcpy.src_addr_widths = PL80X_DMA_BUSWIDTHS; |
| 2339 | pl08x->memcpy.dst_addr_widths = PL80X_DMA_BUSWIDTHS; |
| 2340 | pl08x->memcpy.directions = BIT(DMA_MEM_TO_MEM); |
| 2341 | pl08x->memcpy.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2342 | |
| 2343 | /* Initialize slave engine */ |
| 2344 | dma_cap_set(DMA_SLAVE, pl08x->slave.cap_mask); |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 2345 | dma_cap_set(DMA_CYCLIC, pl08x->slave.cap_mask); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2346 | pl08x->slave.dev = &adev->dev; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2347 | pl08x->slave.device_free_chan_resources = pl08x_free_chan_resources; |
| 2348 | pl08x->slave.device_prep_dma_interrupt = pl08x_prep_dma_interrupt; |
| 2349 | pl08x->slave.device_tx_status = pl08x_dma_tx_status; |
| 2350 | pl08x->slave.device_issue_pending = pl08x_issue_pending; |
| 2351 | pl08x->slave.device_prep_slave_sg = pl08x_prep_slave_sg; |
Alban Bedel | 3b24c20 | 2013-08-11 19:59:20 +0200 | [diff] [blame] | 2352 | pl08x->slave.device_prep_dma_cyclic = pl08x_prep_dma_cyclic; |
Maxime Ripard | bcd1b0b | 2014-11-17 14:42:05 +0100 | [diff] [blame] | 2353 | pl08x->slave.device_config = pl08x_config; |
| 2354 | pl08x->slave.device_pause = pl08x_pause; |
| 2355 | pl08x->slave.device_resume = pl08x_resume; |
| 2356 | pl08x->slave.device_terminate_all = pl08x_terminate_all; |
Mark Brown | ea524c7 | 2015-03-17 23:25:36 +0000 | [diff] [blame] | 2357 | pl08x->slave.src_addr_widths = PL80X_DMA_BUSWIDTHS; |
| 2358 | pl08x->slave.dst_addr_widths = PL80X_DMA_BUSWIDTHS; |
| 2359 | pl08x->slave.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); |
| 2360 | pl08x->slave.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2361 | |
| 2362 | /* Get the platform data */ |
| 2363 | pl08x->pd = dev_get_platdata(&adev->dev); |
| 2364 | if (!pl08x->pd) { |
Linus Walleij | aa4734d | 2015-07-11 14:12:04 +0200 | [diff] [blame] | 2365 | if (np) { |
| 2366 | ret = pl08x_of_probe(adev, pl08x, np); |
| 2367 | if (ret) |
| 2368 | goto out_no_platdata; |
| 2369 | } else { |
| 2370 | dev_err(&adev->dev, "no platform data supplied\n"); |
| 2371 | ret = -EINVAL; |
| 2372 | goto out_no_platdata; |
| 2373 | } |
Sylwester Nawrocki | da6f8ca | 2016-11-10 16:17:49 +0100 | [diff] [blame] | 2374 | } else { |
| 2375 | pl08x->slave.filter.map = pl08x->pd->slave_map; |
| 2376 | pl08x->slave.filter.mapcnt = pl08x->pd->slave_map_len; |
| 2377 | pl08x->slave.filter.fn = pl08x_filter_fn; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2378 | } |
| 2379 | |
Russell King - ARM Linux | 30749cb | 2011-01-03 22:41:13 +0000 | [diff] [blame] | 2380 | /* By default, AHB1 only. If dualmaster, from platform */ |
| 2381 | pl08x->lli_buses = PL08X_AHB1; |
| 2382 | pl08x->mem_buses = PL08X_AHB1; |
| 2383 | if (pl08x->vd->dualmaster) { |
| 2384 | pl08x->lli_buses = pl08x->pd->lli_buses; |
| 2385 | pl08x->mem_buses = pl08x->pd->mem_buses; |
| 2386 | } |
| 2387 | |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 2388 | if (vd->pl080s) |
| 2389 | pl08x->lli_words = PL080S_LLI_WORDS; |
| 2390 | else |
| 2391 | pl08x->lli_words = PL080_LLI_WORDS; |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 2392 | tsfr_size = MAX_NUM_TSFR_LLIS * pl08x->lli_words * sizeof(u32); |
| 2393 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2394 | /* A DMA memory pool for LLIs, align on 1-byte boundary */ |
| 2395 | pl08x->pool = dma_pool_create(DRIVER_NAME, &pl08x->adev->dev, |
Tomasz Figa | ba6785f | 2013-08-11 19:59:15 +0200 | [diff] [blame] | 2396 | tsfr_size, PL08X_ALIGN, 0); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2397 | if (!pl08x->pool) { |
| 2398 | ret = -ENOMEM; |
| 2399 | goto out_no_lli_pool; |
| 2400 | } |
| 2401 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2402 | pl08x->base = ioremap(adev->res.start, resource_size(&adev->res)); |
| 2403 | if (!pl08x->base) { |
| 2404 | ret = -ENOMEM; |
| 2405 | goto out_no_ioremap; |
| 2406 | } |
| 2407 | |
| 2408 | /* Turn on the PL08x */ |
| 2409 | pl08x_ensure_on(pl08x); |
| 2410 | |
Russell King - ARM Linux | 94ae852 | 2011-01-16 20:18:05 +0000 | [diff] [blame] | 2411 | /* Attach the interrupt handler */ |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2412 | writel(0x000000FF, pl08x->base + PL080_ERR_CLEAR); |
| 2413 | writel(0x000000FF, pl08x->base + PL080_TC_CLEAR); |
| 2414 | |
Michael Opdenacker | 174b537 | 2013-10-13 07:10:51 +0200 | [diff] [blame] | 2415 | ret = request_irq(adev->irq[0], pl08x_irq, 0, DRIVER_NAME, pl08x); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2416 | if (ret) { |
| 2417 | dev_err(&adev->dev, "%s failed to request interrupt %d\n", |
| 2418 | __func__, adev->irq[0]); |
| 2419 | goto out_no_irq; |
| 2420 | } |
| 2421 | |
| 2422 | /* Initialize physical channels */ |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 2423 | pl08x->phy_chans = kzalloc((vd->channels * sizeof(*pl08x->phy_chans)), |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2424 | GFP_KERNEL); |
| 2425 | if (!pl08x->phy_chans) { |
Julia Lawall | 983d7be | 2012-08-14 14:58:32 +0200 | [diff] [blame] | 2426 | ret = -ENOMEM; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2427 | goto out_no_phychans; |
| 2428 | } |
| 2429 | |
| 2430 | for (i = 0; i < vd->channels; i++) { |
| 2431 | struct pl08x_phy_chan *ch = &pl08x->phy_chans[i]; |
| 2432 | |
| 2433 | ch->id = i; |
| 2434 | ch->base = pl08x->base + PL080_Cx_BASE(i); |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 2435 | ch->reg_config = ch->base + vd->config_offset; |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2436 | spin_lock_init(&ch->lock); |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 2437 | |
| 2438 | /* |
| 2439 | * Nomadik variants can have channels that are locked |
| 2440 | * down for the secure world only. Lock up these channels |
| 2441 | * by perpetually serving a dummy virtual channel. |
| 2442 | */ |
| 2443 | if (vd->nomadik) { |
| 2444 | u32 val; |
| 2445 | |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 2446 | val = readl(ch->reg_config); |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 2447 | if (val & (PL080N_CONFIG_ITPROT | PL080N_CONFIG_SECPROT)) { |
| 2448 | dev_info(&adev->dev, "physical channel %d reserved for secure access only\n", i); |
| 2449 | ch->locked = true; |
| 2450 | } |
| 2451 | } |
| 2452 | |
Viresh Kumar | 175a5e6 | 2011-08-05 15:32:32 +0530 | [diff] [blame] | 2453 | dev_dbg(&adev->dev, "physical channel %d is %s\n", |
| 2454 | i, pl08x_phy_channel_busy(ch) ? "BUSY" : "FREE"); |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | /* Register as many memcpy channels as there are physical channels */ |
| 2458 | ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->memcpy, |
| 2459 | pl08x->vd->channels, false); |
| 2460 | if (ret <= 0) { |
| 2461 | dev_warn(&pl08x->adev->dev, |
| 2462 | "%s failed to enumerate memcpy channels - %d\n", |
| 2463 | __func__, ret); |
| 2464 | goto out_no_memcpy; |
| 2465 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2466 | |
| 2467 | /* Register slave channels */ |
| 2468 | ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->slave, |
Viresh Kumar | 3e27ee8 | 2011-08-05 15:32:27 +0530 | [diff] [blame] | 2469 | pl08x->pd->num_slave_channels, true); |
Linus Walleij | 1080411 | 2013-12-14 00:16:23 +0100 | [diff] [blame] | 2470 | if (ret < 0) { |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2471 | dev_warn(&pl08x->adev->dev, |
| 2472 | "%s failed to enumerate slave channels - %d\n", |
| 2473 | __func__, ret); |
| 2474 | goto out_no_slave; |
| 2475 | } |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2476 | |
| 2477 | ret = dma_async_device_register(&pl08x->memcpy); |
| 2478 | if (ret) { |
| 2479 | dev_warn(&pl08x->adev->dev, |
| 2480 | "%s failed to register memcpy as an async device - %d\n", |
| 2481 | __func__, ret); |
| 2482 | goto out_no_memcpy_reg; |
| 2483 | } |
| 2484 | |
| 2485 | ret = dma_async_device_register(&pl08x->slave); |
| 2486 | if (ret) { |
| 2487 | dev_warn(&pl08x->adev->dev, |
| 2488 | "%s failed to register slave as an async device - %d\n", |
| 2489 | __func__, ret); |
| 2490 | goto out_no_slave_reg; |
| 2491 | } |
| 2492 | |
| 2493 | amba_set_drvdata(adev, pl08x); |
| 2494 | init_pl08x_debugfs(pl08x); |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 2495 | dev_info(&pl08x->adev->dev, "DMA: PL%03x%s rev%u at 0x%08llx irq %d\n", |
| 2496 | amba_part(adev), pl08x->vd->pl080s ? "s" : "", amba_rev(adev), |
Russell King - ARM Linux | b05cd8f | 2011-01-03 22:33:26 +0000 | [diff] [blame] | 2497 | (unsigned long long)adev->res.start, adev->irq[0]); |
Viresh Kumar | b7b6018 | 2011-08-05 15:32:33 +0530 | [diff] [blame] | 2498 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2499 | return 0; |
| 2500 | |
| 2501 | out_no_slave_reg: |
| 2502 | dma_async_device_unregister(&pl08x->memcpy); |
| 2503 | out_no_memcpy_reg: |
| 2504 | pl08x_free_virtual_channels(&pl08x->slave); |
| 2505 | out_no_slave: |
| 2506 | pl08x_free_virtual_channels(&pl08x->memcpy); |
| 2507 | out_no_memcpy: |
| 2508 | kfree(pl08x->phy_chans); |
| 2509 | out_no_phychans: |
| 2510 | free_irq(adev->irq[0], pl08x); |
| 2511 | out_no_irq: |
| 2512 | iounmap(pl08x->base); |
| 2513 | out_no_ioremap: |
| 2514 | dma_pool_destroy(pl08x->pool); |
| 2515 | out_no_lli_pool: |
| 2516 | out_no_platdata: |
| 2517 | kfree(pl08x); |
| 2518 | out_no_pl08x: |
| 2519 | amba_release_regions(adev); |
| 2520 | return ret; |
| 2521 | } |
| 2522 | |
| 2523 | /* PL080 has 8 channels and the PL080 have just 2 */ |
| 2524 | static struct vendor_data vendor_pl080 = { |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 2525 | .config_offset = PL080_CH_CONFIG, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2526 | .channels = 8, |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2527 | .signals = 16, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2528 | .dualmaster = true, |
Tomasz Figa | 5110e51 | 2013-08-11 19:59:18 +0200 | [diff] [blame] | 2529 | .max_transfer_size = PL080_CONTROL_TRANSFER_SIZE_MASK, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2530 | }; |
| 2531 | |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 2532 | static struct vendor_data vendor_nomadik = { |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 2533 | .config_offset = PL080_CH_CONFIG, |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 2534 | .channels = 8, |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2535 | .signals = 32, |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 2536 | .dualmaster = true, |
| 2537 | .nomadik = true, |
Tomasz Figa | 5110e51 | 2013-08-11 19:59:18 +0200 | [diff] [blame] | 2538 | .max_transfer_size = PL080_CONTROL_TRANSFER_SIZE_MASK, |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 2539 | }; |
| 2540 | |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 2541 | static struct vendor_data vendor_pl080s = { |
| 2542 | .config_offset = PL080S_CH_CONFIG, |
| 2543 | .channels = 8, |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2544 | .signals = 32, |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 2545 | .pl080s = true, |
Tomasz Figa | 5110e51 | 2013-08-11 19:59:18 +0200 | [diff] [blame] | 2546 | .max_transfer_size = PL080S_CONTROL_TRANSFER_SIZE_MASK, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2547 | }; |
| 2548 | |
| 2549 | static struct vendor_data vendor_pl081 = { |
Tomasz Figa | d86ccea | 2013-08-11 19:59:14 +0200 | [diff] [blame] | 2550 | .config_offset = PL080_CH_CONFIG, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2551 | .channels = 2, |
Linus Walleij | f9cd476 | 2016-04-04 22:44:59 +0200 | [diff] [blame] | 2552 | .signals = 16, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2553 | .dualmaster = false, |
Tomasz Figa | 5110e51 | 2013-08-11 19:59:18 +0200 | [diff] [blame] | 2554 | .max_transfer_size = PL080_CONTROL_TRANSFER_SIZE_MASK, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2555 | }; |
| 2556 | |
| 2557 | static struct amba_id pl08x_ids[] = { |
Tomasz Figa | da1b6c0 | 2013-08-11 19:59:17 +0200 | [diff] [blame] | 2558 | /* Samsung PL080S variant */ |
| 2559 | { |
| 2560 | .id = 0x0a141080, |
| 2561 | .mask = 0xffffffff, |
| 2562 | .data = &vendor_pl080s, |
| 2563 | }, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2564 | /* PL080 */ |
| 2565 | { |
| 2566 | .id = 0x00041080, |
| 2567 | .mask = 0x000fffff, |
| 2568 | .data = &vendor_pl080, |
| 2569 | }, |
| 2570 | /* PL081 */ |
| 2571 | { |
| 2572 | .id = 0x00041081, |
| 2573 | .mask = 0x000fffff, |
| 2574 | .data = &vendor_pl081, |
| 2575 | }, |
| 2576 | /* Nomadik 8815 PL080 variant */ |
| 2577 | { |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 2578 | .id = 0x00280080, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2579 | .mask = 0x00ffffff, |
Linus Walleij | affa115 | 2012-04-12 09:01:49 +0200 | [diff] [blame] | 2580 | .data = &vendor_nomadik, |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2581 | }, |
| 2582 | { 0, 0 }, |
| 2583 | }; |
| 2584 | |
Dave Martin | 037566d | 2011-10-05 15:15:20 +0100 | [diff] [blame] | 2585 | MODULE_DEVICE_TABLE(amba, pl08x_ids); |
| 2586 | |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2587 | static struct amba_driver pl08x_amba_driver = { |
| 2588 | .drv.name = DRIVER_NAME, |
| 2589 | .id_table = pl08x_ids, |
| 2590 | .probe = pl08x_probe, |
| 2591 | }; |
| 2592 | |
| 2593 | static int __init pl08x_init(void) |
| 2594 | { |
| 2595 | int retval; |
| 2596 | retval = amba_driver_register(&pl08x_amba_driver); |
| 2597 | if (retval) |
| 2598 | printk(KERN_WARNING DRIVER_NAME |
Russell King - ARM Linux | e8b5e11 | 2011-01-03 22:30:24 +0000 | [diff] [blame] | 2599 | "failed to register as an AMBA device (%d)\n", |
Linus Walleij | e8689e6 | 2010-09-28 15:57:37 +0200 | [diff] [blame] | 2600 | retval); |
| 2601 | return retval; |
| 2602 | } |
| 2603 | subsys_initcall(pl08x_init); |