Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1 | /* |
Per Forlin | d49278e | 2010-12-20 18:31:38 +0100 | [diff] [blame] | 2 | * Copyright (C) Ericsson AB 2007-2008 |
| 3 | * Copyright (C) ST-Ericsson SA 2008-2010 |
Per Forlin | 661385f | 2010-10-06 09:05:28 +0000 | [diff] [blame] | 4 | * Author: Per Forlin <per.forlin@stericsson.com> for ST-Ericsson |
Jonas Aaberg | 767a967 | 2010-08-09 12:08:34 +0000 | [diff] [blame] | 5 | * Author: Jonas Aaberg <jonas.aberg@stericsson.com> for ST-Ericsson |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 6 | * License terms: GNU General Public License (GPL) version 2 |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 9 | #include <linux/dma-mapping.h> |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/slab.h> |
Paul Gortmaker | f492b21 | 2011-07-31 16:17:36 -0400 | [diff] [blame] | 12 | #include <linux/export.h> |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 13 | #include <linux/dmaengine.h> |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/clk.h> |
| 16 | #include <linux/delay.h> |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 17 | #include <linux/pm.h> |
| 18 | #include <linux/pm_runtime.h> |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 19 | #include <linux/err.h> |
Linus Walleij | f4b8976 | 2011-06-27 11:33:46 +0200 | [diff] [blame] | 20 | #include <linux/amba/bus.h> |
Linus Walleij | 15e4b78 | 2012-04-12 18:12:43 +0200 | [diff] [blame] | 21 | #include <linux/regulator/consumer.h> |
Linus Walleij | 865fab6 | 2012-10-18 14:20:16 +0200 | [diff] [blame] | 22 | #include <linux/platform_data/dma-ste-dma40.h> |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 23 | |
Russell King - ARM Linux | d2ebfb3 | 2012-03-06 22:34:26 +0000 | [diff] [blame] | 24 | #include "dmaengine.h" |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 25 | #include "ste_dma40_ll.h" |
| 26 | |
| 27 | #define D40_NAME "dma40" |
| 28 | |
| 29 | #define D40_PHY_CHAN -1 |
| 30 | |
| 31 | /* For masking out/in 2 bit channel positions */ |
| 32 | #define D40_CHAN_POS(chan) (2 * (chan / 2)) |
| 33 | #define D40_CHAN_POS_MASK(chan) (0x3 << D40_CHAN_POS(chan)) |
| 34 | |
| 35 | /* Maximum iterations taken before giving up suspending a channel */ |
| 36 | #define D40_SUSPEND_MAX_IT 500 |
| 37 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 38 | /* Milliseconds */ |
| 39 | #define DMA40_AUTOSUSPEND_DELAY 100 |
| 40 | |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 41 | /* Hardware requirement on LCLA alignment */ |
| 42 | #define LCLA_ALIGNMENT 0x40000 |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 43 | |
| 44 | /* Max number of links per event group */ |
| 45 | #define D40_LCLA_LINK_PER_EVENT_GRP 128 |
| 46 | #define D40_LCLA_END D40_LCLA_LINK_PER_EVENT_GRP |
| 47 | |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 48 | /* Attempts before giving up to trying to get pages that are aligned */ |
| 49 | #define MAX_LCLA_ALLOC_ATTEMPTS 256 |
| 50 | |
| 51 | /* Bit markings for allocation map */ |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 52 | #define D40_ALLOC_FREE (1 << 31) |
| 53 | #define D40_ALLOC_PHY (1 << 30) |
| 54 | #define D40_ALLOC_LOG_FREE 0 |
| 55 | |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 56 | #define MAX(a, b) (((a) < (b)) ? (b) : (a)) |
| 57 | |
Lee Jones | 664a57e | 2013-05-03 15:31:53 +0100 | [diff] [blame] | 58 | /* Reserved event lines for memcpy only. */ |
Linus Walleij | a2acaa2 | 2013-05-03 21:46:09 +0200 | [diff] [blame^] | 59 | #define DB8500_DMA_MEMCPY_EV_0 51 |
| 60 | #define DB8500_DMA_MEMCPY_EV_1 56 |
| 61 | #define DB8500_DMA_MEMCPY_EV_2 57 |
| 62 | #define DB8500_DMA_MEMCPY_EV_3 58 |
| 63 | #define DB8500_DMA_MEMCPY_EV_4 59 |
| 64 | #define DB8500_DMA_MEMCPY_EV_5 60 |
| 65 | |
| 66 | static int dma40_memcpy_channels[] = { |
| 67 | DB8500_DMA_MEMCPY_EV_0, |
| 68 | DB8500_DMA_MEMCPY_EV_1, |
| 69 | DB8500_DMA_MEMCPY_EV_2, |
| 70 | DB8500_DMA_MEMCPY_EV_3, |
| 71 | DB8500_DMA_MEMCPY_EV_4, |
| 72 | DB8500_DMA_MEMCPY_EV_5, |
| 73 | }; |
Lee Jones | 664a57e | 2013-05-03 15:31:53 +0100 | [diff] [blame] | 74 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 75 | /** |
| 76 | * enum 40_command - The different commands and/or statuses. |
| 77 | * |
| 78 | * @D40_DMA_STOP: DMA channel command STOP or status STOPPED, |
| 79 | * @D40_DMA_RUN: The DMA channel is RUNNING of the command RUN. |
| 80 | * @D40_DMA_SUSPEND_REQ: Request the DMA to SUSPEND as soon as possible. |
| 81 | * @D40_DMA_SUSPENDED: The DMA channel is SUSPENDED. |
| 82 | */ |
| 83 | enum d40_command { |
| 84 | D40_DMA_STOP = 0, |
| 85 | D40_DMA_RUN = 1, |
| 86 | D40_DMA_SUSPEND_REQ = 2, |
| 87 | D40_DMA_SUSPENDED = 3 |
| 88 | }; |
| 89 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 90 | /* |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 91 | * enum d40_events - The different Event Enables for the event lines. |
| 92 | * |
| 93 | * @D40_DEACTIVATE_EVENTLINE: De-activate Event line, stopping the logical chan. |
| 94 | * @D40_ACTIVATE_EVENTLINE: Activate the Event line, to start a logical chan. |
| 95 | * @D40_SUSPEND_REQ_EVENTLINE: Requesting for suspending a event line. |
| 96 | * @D40_ROUND_EVENTLINE: Status check for event line. |
| 97 | */ |
| 98 | |
| 99 | enum d40_events { |
| 100 | D40_DEACTIVATE_EVENTLINE = 0, |
| 101 | D40_ACTIVATE_EVENTLINE = 1, |
| 102 | D40_SUSPEND_REQ_EVENTLINE = 2, |
| 103 | D40_ROUND_EVENTLINE = 3 |
| 104 | }; |
| 105 | |
| 106 | /* |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 107 | * These are the registers that has to be saved and later restored |
| 108 | * when the DMA hw is powered off. |
| 109 | * TODO: Add save/restore of D40_DREG_GCC on dma40 v3 or later, if that works. |
| 110 | */ |
| 111 | static u32 d40_backup_regs[] = { |
| 112 | D40_DREG_LCPA, |
| 113 | D40_DREG_LCLA, |
| 114 | D40_DREG_PRMSE, |
| 115 | D40_DREG_PRMSO, |
| 116 | D40_DREG_PRMOE, |
| 117 | D40_DREG_PRMOO, |
| 118 | }; |
| 119 | |
| 120 | #define BACKUP_REGS_SZ ARRAY_SIZE(d40_backup_regs) |
| 121 | |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 122 | /* |
| 123 | * since 9540 and 8540 has the same HW revision |
| 124 | * use v4a for 9540 or ealier |
| 125 | * use v4b for 8540 or later |
| 126 | * HW revision: |
| 127 | * DB8500ed has revision 0 |
| 128 | * DB8500v1 has revision 2 |
| 129 | * DB8500v2 has revision 3 |
| 130 | * AP9540v1 has revision 4 |
| 131 | * DB8540v1 has revision 4 |
| 132 | * TODO: Check if all these registers have to be saved/restored on dma40 v4a |
| 133 | */ |
| 134 | static u32 d40_backup_regs_v4a[] = { |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 135 | D40_DREG_PSEG1, |
| 136 | D40_DREG_PSEG2, |
| 137 | D40_DREG_PSEG3, |
| 138 | D40_DREG_PSEG4, |
| 139 | D40_DREG_PCEG1, |
| 140 | D40_DREG_PCEG2, |
| 141 | D40_DREG_PCEG3, |
| 142 | D40_DREG_PCEG4, |
| 143 | D40_DREG_RSEG1, |
| 144 | D40_DREG_RSEG2, |
| 145 | D40_DREG_RSEG3, |
| 146 | D40_DREG_RSEG4, |
| 147 | D40_DREG_RCEG1, |
| 148 | D40_DREG_RCEG2, |
| 149 | D40_DREG_RCEG3, |
| 150 | D40_DREG_RCEG4, |
| 151 | }; |
| 152 | |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 153 | #define BACKUP_REGS_SZ_V4A ARRAY_SIZE(d40_backup_regs_v4a) |
| 154 | |
| 155 | static u32 d40_backup_regs_v4b[] = { |
| 156 | D40_DREG_CPSEG1, |
| 157 | D40_DREG_CPSEG2, |
| 158 | D40_DREG_CPSEG3, |
| 159 | D40_DREG_CPSEG4, |
| 160 | D40_DREG_CPSEG5, |
| 161 | D40_DREG_CPCEG1, |
| 162 | D40_DREG_CPCEG2, |
| 163 | D40_DREG_CPCEG3, |
| 164 | D40_DREG_CPCEG4, |
| 165 | D40_DREG_CPCEG5, |
| 166 | D40_DREG_CRSEG1, |
| 167 | D40_DREG_CRSEG2, |
| 168 | D40_DREG_CRSEG3, |
| 169 | D40_DREG_CRSEG4, |
| 170 | D40_DREG_CRSEG5, |
| 171 | D40_DREG_CRCEG1, |
| 172 | D40_DREG_CRCEG2, |
| 173 | D40_DREG_CRCEG3, |
| 174 | D40_DREG_CRCEG4, |
| 175 | D40_DREG_CRCEG5, |
| 176 | }; |
| 177 | |
| 178 | #define BACKUP_REGS_SZ_V4B ARRAY_SIZE(d40_backup_regs_v4b) |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 179 | |
| 180 | static u32 d40_backup_regs_chan[] = { |
| 181 | D40_CHAN_REG_SSCFG, |
| 182 | D40_CHAN_REG_SSELT, |
| 183 | D40_CHAN_REG_SSPTR, |
| 184 | D40_CHAN_REG_SSLNK, |
| 185 | D40_CHAN_REG_SDCFG, |
| 186 | D40_CHAN_REG_SDELT, |
| 187 | D40_CHAN_REG_SDPTR, |
| 188 | D40_CHAN_REG_SDLNK, |
| 189 | }; |
| 190 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 191 | /** |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 192 | * struct d40_interrupt_lookup - lookup table for interrupt handler |
| 193 | * |
| 194 | * @src: Interrupt mask register. |
| 195 | * @clr: Interrupt clear register. |
| 196 | * @is_error: true if this is an error interrupt. |
| 197 | * @offset: start delta in the lookup_log_chans in d40_base. If equals to |
| 198 | * D40_PHY_CHAN, the lookup_phy_chans shall be used instead. |
| 199 | */ |
| 200 | struct d40_interrupt_lookup { |
| 201 | u32 src; |
| 202 | u32 clr; |
| 203 | bool is_error; |
| 204 | int offset; |
| 205 | }; |
| 206 | |
| 207 | |
| 208 | static struct d40_interrupt_lookup il_v4a[] = { |
| 209 | {D40_DREG_LCTIS0, D40_DREG_LCICR0, false, 0}, |
| 210 | {D40_DREG_LCTIS1, D40_DREG_LCICR1, false, 32}, |
| 211 | {D40_DREG_LCTIS2, D40_DREG_LCICR2, false, 64}, |
| 212 | {D40_DREG_LCTIS3, D40_DREG_LCICR3, false, 96}, |
| 213 | {D40_DREG_LCEIS0, D40_DREG_LCICR0, true, 0}, |
| 214 | {D40_DREG_LCEIS1, D40_DREG_LCICR1, true, 32}, |
| 215 | {D40_DREG_LCEIS2, D40_DREG_LCICR2, true, 64}, |
| 216 | {D40_DREG_LCEIS3, D40_DREG_LCICR3, true, 96}, |
| 217 | {D40_DREG_PCTIS, D40_DREG_PCICR, false, D40_PHY_CHAN}, |
| 218 | {D40_DREG_PCEIS, D40_DREG_PCICR, true, D40_PHY_CHAN}, |
| 219 | }; |
| 220 | |
| 221 | static struct d40_interrupt_lookup il_v4b[] = { |
| 222 | {D40_DREG_CLCTIS1, D40_DREG_CLCICR1, false, 0}, |
| 223 | {D40_DREG_CLCTIS2, D40_DREG_CLCICR2, false, 32}, |
| 224 | {D40_DREG_CLCTIS3, D40_DREG_CLCICR3, false, 64}, |
| 225 | {D40_DREG_CLCTIS4, D40_DREG_CLCICR4, false, 96}, |
| 226 | {D40_DREG_CLCTIS5, D40_DREG_CLCICR5, false, 128}, |
| 227 | {D40_DREG_CLCEIS1, D40_DREG_CLCICR1, true, 0}, |
| 228 | {D40_DREG_CLCEIS2, D40_DREG_CLCICR2, true, 32}, |
| 229 | {D40_DREG_CLCEIS3, D40_DREG_CLCICR3, true, 64}, |
| 230 | {D40_DREG_CLCEIS4, D40_DREG_CLCICR4, true, 96}, |
| 231 | {D40_DREG_CLCEIS5, D40_DREG_CLCICR5, true, 128}, |
| 232 | {D40_DREG_CPCTIS, D40_DREG_CPCICR, false, D40_PHY_CHAN}, |
| 233 | {D40_DREG_CPCEIS, D40_DREG_CPCICR, true, D40_PHY_CHAN}, |
| 234 | }; |
| 235 | |
| 236 | /** |
| 237 | * struct d40_reg_val - simple lookup struct |
| 238 | * |
| 239 | * @reg: The register. |
| 240 | * @val: The value that belongs to the register in reg. |
| 241 | */ |
| 242 | struct d40_reg_val { |
| 243 | unsigned int reg; |
| 244 | unsigned int val; |
| 245 | }; |
| 246 | |
| 247 | static __initdata struct d40_reg_val dma_init_reg_v4a[] = { |
| 248 | /* Clock every part of the DMA block from start */ |
| 249 | { .reg = D40_DREG_GCC, .val = D40_DREG_GCC_ENABLE_ALL}, |
| 250 | |
| 251 | /* Interrupts on all logical channels */ |
| 252 | { .reg = D40_DREG_LCMIS0, .val = 0xFFFFFFFF}, |
| 253 | { .reg = D40_DREG_LCMIS1, .val = 0xFFFFFFFF}, |
| 254 | { .reg = D40_DREG_LCMIS2, .val = 0xFFFFFFFF}, |
| 255 | { .reg = D40_DREG_LCMIS3, .val = 0xFFFFFFFF}, |
| 256 | { .reg = D40_DREG_LCICR0, .val = 0xFFFFFFFF}, |
| 257 | { .reg = D40_DREG_LCICR1, .val = 0xFFFFFFFF}, |
| 258 | { .reg = D40_DREG_LCICR2, .val = 0xFFFFFFFF}, |
| 259 | { .reg = D40_DREG_LCICR3, .val = 0xFFFFFFFF}, |
| 260 | { .reg = D40_DREG_LCTIS0, .val = 0xFFFFFFFF}, |
| 261 | { .reg = D40_DREG_LCTIS1, .val = 0xFFFFFFFF}, |
| 262 | { .reg = D40_DREG_LCTIS2, .val = 0xFFFFFFFF}, |
| 263 | { .reg = D40_DREG_LCTIS3, .val = 0xFFFFFFFF} |
| 264 | }; |
| 265 | static __initdata struct d40_reg_val dma_init_reg_v4b[] = { |
| 266 | /* Clock every part of the DMA block from start */ |
| 267 | { .reg = D40_DREG_GCC, .val = D40_DREG_GCC_ENABLE_ALL}, |
| 268 | |
| 269 | /* Interrupts on all logical channels */ |
| 270 | { .reg = D40_DREG_CLCMIS1, .val = 0xFFFFFFFF}, |
| 271 | { .reg = D40_DREG_CLCMIS2, .val = 0xFFFFFFFF}, |
| 272 | { .reg = D40_DREG_CLCMIS3, .val = 0xFFFFFFFF}, |
| 273 | { .reg = D40_DREG_CLCMIS4, .val = 0xFFFFFFFF}, |
| 274 | { .reg = D40_DREG_CLCMIS5, .val = 0xFFFFFFFF}, |
| 275 | { .reg = D40_DREG_CLCICR1, .val = 0xFFFFFFFF}, |
| 276 | { .reg = D40_DREG_CLCICR2, .val = 0xFFFFFFFF}, |
| 277 | { .reg = D40_DREG_CLCICR3, .val = 0xFFFFFFFF}, |
| 278 | { .reg = D40_DREG_CLCICR4, .val = 0xFFFFFFFF}, |
| 279 | { .reg = D40_DREG_CLCICR5, .val = 0xFFFFFFFF}, |
| 280 | { .reg = D40_DREG_CLCTIS1, .val = 0xFFFFFFFF}, |
| 281 | { .reg = D40_DREG_CLCTIS2, .val = 0xFFFFFFFF}, |
| 282 | { .reg = D40_DREG_CLCTIS3, .val = 0xFFFFFFFF}, |
| 283 | { .reg = D40_DREG_CLCTIS4, .val = 0xFFFFFFFF}, |
| 284 | { .reg = D40_DREG_CLCTIS5, .val = 0xFFFFFFFF} |
| 285 | }; |
| 286 | |
| 287 | /** |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 288 | * struct d40_lli_pool - Structure for keeping LLIs in memory |
| 289 | * |
| 290 | * @base: Pointer to memory area when the pre_alloc_lli's are not large |
| 291 | * enough, IE bigger than the most common case, 1 dst and 1 src. NULL if |
| 292 | * pre_alloc_lli is used. |
Rabin Vincent | b00f938 | 2011-01-25 11:18:15 +0100 | [diff] [blame] | 293 | * @dma_addr: DMA address, if mapped |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 294 | * @size: The size in bytes of the memory at base or the size of pre_alloc_lli. |
| 295 | * @pre_alloc_lli: Pre allocated area for the most common case of transfers, |
| 296 | * one buffer to one buffer. |
| 297 | */ |
| 298 | struct d40_lli_pool { |
| 299 | void *base; |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 300 | int size; |
Rabin Vincent | b00f938 | 2011-01-25 11:18:15 +0100 | [diff] [blame] | 301 | dma_addr_t dma_addr; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 302 | /* Space for dst and src, plus an extra for padding */ |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 303 | u8 pre_alloc_lli[3 * sizeof(struct d40_phy_lli)]; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | /** |
| 307 | * struct d40_desc - A descriptor is one DMA job. |
| 308 | * |
| 309 | * @lli_phy: LLI settings for physical channel. Both src and dst= |
| 310 | * points into the lli_pool, to base if lli_len > 1 or to pre_alloc_lli if |
| 311 | * lli_len equals one. |
| 312 | * @lli_log: Same as above but for logical channels. |
| 313 | * @lli_pool: The pool with two entries pre-allocated. |
Per Friden | 941b77a | 2010-06-20 21:24:45 +0000 | [diff] [blame] | 314 | * @lli_len: Number of llis of current descriptor. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 315 | * @lli_current: Number of transferred llis. |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 316 | * @lcla_alloc: Number of LCLA entries allocated. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 317 | * @txd: DMA engine struct. Used for among other things for communication |
| 318 | * during a transfer. |
| 319 | * @node: List entry. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 320 | * @is_in_client_list: true if the client owns this descriptor. |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 321 | * @cyclic: true if this is a cyclic job |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 322 | * |
| 323 | * This descriptor is used for both logical and physical transfers. |
| 324 | */ |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 325 | struct d40_desc { |
| 326 | /* LLI physical */ |
| 327 | struct d40_phy_lli_bidir lli_phy; |
| 328 | /* LLI logical */ |
| 329 | struct d40_log_lli_bidir lli_log; |
| 330 | |
| 331 | struct d40_lli_pool lli_pool; |
Per Friden | 941b77a | 2010-06-20 21:24:45 +0000 | [diff] [blame] | 332 | int lli_len; |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 333 | int lli_current; |
| 334 | int lcla_alloc; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 335 | |
| 336 | struct dma_async_tx_descriptor txd; |
| 337 | struct list_head node; |
| 338 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 339 | bool is_in_client_list; |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 340 | bool cyclic; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 341 | }; |
| 342 | |
| 343 | /** |
| 344 | * struct d40_lcla_pool - LCLA pool settings and data. |
| 345 | * |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 346 | * @base: The virtual address of LCLA. 18 bit aligned. |
| 347 | * @base_unaligned: The orignal kmalloc pointer, if kmalloc is used. |
| 348 | * This pointer is only there for clean-up on error. |
| 349 | * @pages: The number of pages needed for all physical channels. |
| 350 | * Only used later for clean-up on error |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 351 | * @lock: Lock to protect the content in this struct. |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 352 | * @alloc_map: big map over which LCLA entry is own by which job. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 353 | */ |
| 354 | struct d40_lcla_pool { |
| 355 | void *base; |
Rabin Vincent | 026cbc4 | 2011-01-25 11:18:14 +0100 | [diff] [blame] | 356 | dma_addr_t dma_addr; |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 357 | void *base_unaligned; |
| 358 | int pages; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 359 | spinlock_t lock; |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 360 | struct d40_desc **alloc_map; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 361 | }; |
| 362 | |
| 363 | /** |
| 364 | * struct d40_phy_res - struct for handling eventlines mapped to physical |
| 365 | * channels. |
| 366 | * |
| 367 | * @lock: A lock protection this entity. |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 368 | * @reserved: True if used by secure world or otherwise. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 369 | * @num: The physical channel number of this entity. |
| 370 | * @allocated_src: Bit mapped to show which src event line's are mapped to |
| 371 | * this physical channel. Can also be free or physically allocated. |
| 372 | * @allocated_dst: Same as for src but is dst. |
| 373 | * allocated_dst and allocated_src uses the D40_ALLOC* defines as well as |
Jonas Aaberg | 767a967 | 2010-08-09 12:08:34 +0000 | [diff] [blame] | 374 | * event line number. |
Fabio Baltieri | 7407048 | 2012-12-18 12:25:14 +0100 | [diff] [blame] | 375 | * @use_soft_lli: To mark if the linked lists of channel are managed by SW. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 376 | */ |
| 377 | struct d40_phy_res { |
| 378 | spinlock_t lock; |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 379 | bool reserved; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 380 | int num; |
| 381 | u32 allocated_src; |
| 382 | u32 allocated_dst; |
Fabio Baltieri | 7407048 | 2012-12-18 12:25:14 +0100 | [diff] [blame] | 383 | bool use_soft_lli; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 384 | }; |
| 385 | |
| 386 | struct d40_base; |
| 387 | |
| 388 | /** |
| 389 | * struct d40_chan - Struct that describes a channel. |
| 390 | * |
| 391 | * @lock: A spinlock to protect this struct. |
| 392 | * @log_num: The logical number, if any of this channel. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 393 | * @pending_tx: The number of pending transfers. Used between interrupt handler |
| 394 | * and tasklet. |
| 395 | * @busy: Set to true when transfer is ongoing on this channel. |
Jonas Aaberg | 2a61434 | 2010-06-20 21:25:24 +0000 | [diff] [blame] | 396 | * @phy_chan: Pointer to physical channel which this instance runs on. If this |
| 397 | * point is NULL, then the channel is not allocated. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 398 | * @chan: DMA engine handle. |
| 399 | * @tasklet: Tasklet that gets scheduled from interrupt context to complete a |
| 400 | * transfer and call client callback. |
| 401 | * @client: Cliented owned descriptor list. |
Per Forlin | da063d2 | 2011-08-29 13:33:32 +0200 | [diff] [blame] | 402 | * @pending_queue: Submitted jobs, to be issued by issue_pending() |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 403 | * @active: Active descriptor. |
Fabio Baltieri | 4226dd8 | 2012-12-13 13:46:16 +0100 | [diff] [blame] | 404 | * @done: Completed jobs |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 405 | * @queue: Queued jobs. |
Per Forlin | 82babbb36 | 2011-08-29 13:33:35 +0200 | [diff] [blame] | 406 | * @prepare_queue: Prepared jobs. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 407 | * @dma_cfg: The client configuration of this dma channel. |
Rabin Vincent | ce2ca12 | 2010-10-12 13:00:49 +0000 | [diff] [blame] | 408 | * @configured: whether the dma_cfg configuration is valid |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 409 | * @base: Pointer to the device instance struct. |
| 410 | * @src_def_cfg: Default cfg register setting for src. |
| 411 | * @dst_def_cfg: Default cfg register setting for dst. |
| 412 | * @log_def: Default logical channel settings. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 413 | * @lcpa: Pointer to dst and src lcpa settings. |
om prakash | ae752bf | 2011-06-27 11:33:31 +0200 | [diff] [blame] | 414 | * @runtime_addr: runtime configured address. |
| 415 | * @runtime_direction: runtime configured direction. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 416 | * |
| 417 | * This struct can either "be" a logical or a physical channel. |
| 418 | */ |
| 419 | struct d40_chan { |
| 420 | spinlock_t lock; |
| 421 | int log_num; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 422 | int pending_tx; |
| 423 | bool busy; |
| 424 | struct d40_phy_res *phy_chan; |
| 425 | struct dma_chan chan; |
| 426 | struct tasklet_struct tasklet; |
| 427 | struct list_head client; |
Per Forlin | a8f3067 | 2011-06-26 23:29:52 +0200 | [diff] [blame] | 428 | struct list_head pending_queue; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 429 | struct list_head active; |
Fabio Baltieri | 4226dd8 | 2012-12-13 13:46:16 +0100 | [diff] [blame] | 430 | struct list_head done; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 431 | struct list_head queue; |
Per Forlin | 82babbb36 | 2011-08-29 13:33:35 +0200 | [diff] [blame] | 432 | struct list_head prepare_queue; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 433 | struct stedma40_chan_cfg dma_cfg; |
Rabin Vincent | ce2ca12 | 2010-10-12 13:00:49 +0000 | [diff] [blame] | 434 | bool configured; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 435 | struct d40_base *base; |
| 436 | /* Default register configurations */ |
| 437 | u32 src_def_cfg; |
| 438 | u32 dst_def_cfg; |
| 439 | struct d40_def_lcsp log_def; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 440 | struct d40_log_lli_full *lcpa; |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 441 | /* Runtime reconfiguration */ |
| 442 | dma_addr_t runtime_addr; |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 443 | enum dma_transfer_direction runtime_direction; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 444 | }; |
| 445 | |
| 446 | /** |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 447 | * struct d40_gen_dmac - generic values to represent u8500/u8540 DMA |
| 448 | * controller |
| 449 | * |
| 450 | * @backup: the pointer to the registers address array for backup |
| 451 | * @backup_size: the size of the registers address array for backup |
| 452 | * @realtime_en: the realtime enable register |
| 453 | * @realtime_clear: the realtime clear register |
| 454 | * @high_prio_en: the high priority enable register |
| 455 | * @high_prio_clear: the high priority clear register |
| 456 | * @interrupt_en: the interrupt enable register |
| 457 | * @interrupt_clear: the interrupt clear register |
| 458 | * @il: the pointer to struct d40_interrupt_lookup |
| 459 | * @il_size: the size of d40_interrupt_lookup array |
| 460 | * @init_reg: the pointer to the struct d40_reg_val |
| 461 | * @init_reg_size: the size of d40_reg_val array |
| 462 | */ |
| 463 | struct d40_gen_dmac { |
| 464 | u32 *backup; |
| 465 | u32 backup_size; |
| 466 | u32 realtime_en; |
| 467 | u32 realtime_clear; |
| 468 | u32 high_prio_en; |
| 469 | u32 high_prio_clear; |
| 470 | u32 interrupt_en; |
| 471 | u32 interrupt_clear; |
| 472 | struct d40_interrupt_lookup *il; |
| 473 | u32 il_size; |
| 474 | struct d40_reg_val *init_reg; |
| 475 | u32 init_reg_size; |
| 476 | }; |
| 477 | |
| 478 | /** |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 479 | * struct d40_base - The big global struct, one for each probe'd instance. |
| 480 | * |
| 481 | * @interrupt_lock: Lock used to make sure one interrupt is handle a time. |
| 482 | * @execmd_lock: Lock for execute command usage since several channels share |
| 483 | * the same physical register. |
| 484 | * @dev: The device structure. |
| 485 | * @virtbase: The virtual base address of the DMA's register. |
Linus Walleij | f418559 | 2010-06-22 18:06:42 -0700 | [diff] [blame] | 486 | * @rev: silicon revision detected. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 487 | * @clk: Pointer to the DMA clock structure. |
| 488 | * @phy_start: Physical memory start of the DMA registers. |
| 489 | * @phy_size: Size of the DMA register map. |
| 490 | * @irq: The IRQ number. |
| 491 | * @num_phy_chans: The number of physical channels. Read from HW. This |
| 492 | * is the number of available channels for this driver, not counting "Secure |
| 493 | * mode" allocated physical channels. |
| 494 | * @num_log_chans: The number of logical channels. Calculated from |
| 495 | * num_phy_chans. |
| 496 | * @dma_both: dma_device channels that can do both memcpy and slave transfers. |
| 497 | * @dma_slave: dma_device channels that can do only do slave transfers. |
| 498 | * @dma_memcpy: dma_device channels that can do only do memcpy transfers. |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 499 | * @phy_chans: Room for all possible physical channels in system. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 500 | * @log_chans: Room for all possible logical channels in system. |
| 501 | * @lookup_log_chans: Used to map interrupt number to logical channel. Points |
| 502 | * to log_chans entries. |
| 503 | * @lookup_phy_chans: Used to map interrupt number to physical channel. Points |
| 504 | * to phy_chans entries. |
| 505 | * @plat_data: Pointer to provided platform_data which is the driver |
| 506 | * configuration. |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 507 | * @lcpa_regulator: Pointer to hold the regulator for the esram bank for lcla. |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 508 | * @phy_res: Vector containing all physical channels. |
| 509 | * @lcla_pool: lcla pool settings and data. |
| 510 | * @lcpa_base: The virtual mapped address of LCPA. |
| 511 | * @phy_lcpa: The physical address of the LCPA. |
| 512 | * @lcpa_size: The size of the LCPA area. |
Jonas Aaberg | c675b1b | 2010-06-20 21:25:08 +0000 | [diff] [blame] | 513 | * @desc_slab: cache for descriptors. |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 514 | * @reg_val_backup: Here the values of some hardware registers are stored |
| 515 | * before the DMA is powered off. They are restored when the power is back on. |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 516 | * @reg_val_backup_v4: Backup of registers that only exits on dma40 v3 and |
| 517 | * later |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 518 | * @reg_val_backup_chan: Backup data for standard channel parameter registers. |
| 519 | * @gcc_pwr_off_mask: Mask to maintain the channels that can be turned off. |
| 520 | * @initialized: true if the dma has been initialized |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 521 | * @gen_dmac: the struct for generic registers values to represent u8500/8540 |
| 522 | * DMA controller |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 523 | */ |
| 524 | struct d40_base { |
| 525 | spinlock_t interrupt_lock; |
| 526 | spinlock_t execmd_lock; |
| 527 | struct device *dev; |
| 528 | void __iomem *virtbase; |
Linus Walleij | f418559 | 2010-06-22 18:06:42 -0700 | [diff] [blame] | 529 | u8 rev:4; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 530 | struct clk *clk; |
| 531 | phys_addr_t phy_start; |
| 532 | resource_size_t phy_size; |
| 533 | int irq; |
| 534 | int num_phy_chans; |
| 535 | int num_log_chans; |
Per Forlin | b96710e | 2011-10-18 18:39:47 +0200 | [diff] [blame] | 536 | struct device_dma_parameters dma_parms; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 537 | struct dma_device dma_both; |
| 538 | struct dma_device dma_slave; |
| 539 | struct dma_device dma_memcpy; |
| 540 | struct d40_chan *phy_chans; |
| 541 | struct d40_chan *log_chans; |
| 542 | struct d40_chan **lookup_log_chans; |
| 543 | struct d40_chan **lookup_phy_chans; |
| 544 | struct stedma40_platform_data *plat_data; |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 545 | struct regulator *lcpa_regulator; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 546 | /* Physical half channels */ |
| 547 | struct d40_phy_res *phy_res; |
| 548 | struct d40_lcla_pool lcla_pool; |
| 549 | void *lcpa_base; |
| 550 | dma_addr_t phy_lcpa; |
| 551 | resource_size_t lcpa_size; |
Jonas Aaberg | c675b1b | 2010-06-20 21:25:08 +0000 | [diff] [blame] | 552 | struct kmem_cache *desc_slab; |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 553 | u32 reg_val_backup[BACKUP_REGS_SZ]; |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 554 | u32 reg_val_backup_v4[MAX(BACKUP_REGS_SZ_V4A, BACKUP_REGS_SZ_V4B)]; |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 555 | u32 *reg_val_backup_chan; |
| 556 | u16 gcc_pwr_off_mask; |
| 557 | bool initialized; |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 558 | struct d40_gen_dmac gen_dmac; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 559 | }; |
| 560 | |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 561 | static struct device *chan2dev(struct d40_chan *d40c) |
| 562 | { |
| 563 | return &d40c->chan.dev->device; |
| 564 | } |
| 565 | |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 566 | static bool chan_is_physical(struct d40_chan *chan) |
| 567 | { |
| 568 | return chan->log_num == D40_PHY_CHAN; |
| 569 | } |
| 570 | |
| 571 | static bool chan_is_logical(struct d40_chan *chan) |
| 572 | { |
| 573 | return !chan_is_physical(chan); |
| 574 | } |
| 575 | |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 576 | static void __iomem *chan_base(struct d40_chan *chan) |
| 577 | { |
| 578 | return chan->base->virtbase + D40_DREG_PCBASE + |
| 579 | chan->phy_chan->num * D40_DREG_PCDELTA; |
| 580 | } |
| 581 | |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 582 | #define d40_err(dev, format, arg...) \ |
| 583 | dev_err(dev, "[%s] " format, __func__, ## arg) |
| 584 | |
| 585 | #define chan_err(d40c, format, arg...) \ |
| 586 | d40_err(chan2dev(d40c), format, ## arg) |
| 587 | |
Rabin Vincent | b00f938 | 2011-01-25 11:18:15 +0100 | [diff] [blame] | 588 | static int d40_pool_lli_alloc(struct d40_chan *d40c, struct d40_desc *d40d, |
Rabin Vincent | dbd8878 | 2011-01-25 11:18:19 +0100 | [diff] [blame] | 589 | int lli_len) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 590 | { |
Rabin Vincent | dbd8878 | 2011-01-25 11:18:19 +0100 | [diff] [blame] | 591 | bool is_log = chan_is_logical(d40c); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 592 | u32 align; |
| 593 | void *base; |
| 594 | |
| 595 | if (is_log) |
| 596 | align = sizeof(struct d40_log_lli); |
| 597 | else |
| 598 | align = sizeof(struct d40_phy_lli); |
| 599 | |
| 600 | if (lli_len == 1) { |
| 601 | base = d40d->lli_pool.pre_alloc_lli; |
| 602 | d40d->lli_pool.size = sizeof(d40d->lli_pool.pre_alloc_lli); |
| 603 | d40d->lli_pool.base = NULL; |
| 604 | } else { |
Rabin Vincent | 594ece4 | 2011-01-25 11:18:12 +0100 | [diff] [blame] | 605 | d40d->lli_pool.size = lli_len * 2 * align; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 606 | |
| 607 | base = kmalloc(d40d->lli_pool.size + align, GFP_NOWAIT); |
| 608 | d40d->lli_pool.base = base; |
| 609 | |
| 610 | if (d40d->lli_pool.base == NULL) |
| 611 | return -ENOMEM; |
| 612 | } |
| 613 | |
| 614 | if (is_log) { |
Rabin Vincent | d924aba | 2011-01-25 11:18:16 +0100 | [diff] [blame] | 615 | d40d->lli_log.src = PTR_ALIGN(base, align); |
Rabin Vincent | 594ece4 | 2011-01-25 11:18:12 +0100 | [diff] [blame] | 616 | d40d->lli_log.dst = d40d->lli_log.src + lli_len; |
Rabin Vincent | b00f938 | 2011-01-25 11:18:15 +0100 | [diff] [blame] | 617 | |
| 618 | d40d->lli_pool.dma_addr = 0; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 619 | } else { |
Rabin Vincent | d924aba | 2011-01-25 11:18:16 +0100 | [diff] [blame] | 620 | d40d->lli_phy.src = PTR_ALIGN(base, align); |
Rabin Vincent | 594ece4 | 2011-01-25 11:18:12 +0100 | [diff] [blame] | 621 | d40d->lli_phy.dst = d40d->lli_phy.src + lli_len; |
Rabin Vincent | b00f938 | 2011-01-25 11:18:15 +0100 | [diff] [blame] | 622 | |
| 623 | d40d->lli_pool.dma_addr = dma_map_single(d40c->base->dev, |
| 624 | d40d->lli_phy.src, |
| 625 | d40d->lli_pool.size, |
| 626 | DMA_TO_DEVICE); |
| 627 | |
| 628 | if (dma_mapping_error(d40c->base->dev, |
| 629 | d40d->lli_pool.dma_addr)) { |
| 630 | kfree(d40d->lli_pool.base); |
| 631 | d40d->lli_pool.base = NULL; |
| 632 | d40d->lli_pool.dma_addr = 0; |
| 633 | return -ENOMEM; |
| 634 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | return 0; |
| 638 | } |
| 639 | |
Rabin Vincent | b00f938 | 2011-01-25 11:18:15 +0100 | [diff] [blame] | 640 | static void d40_pool_lli_free(struct d40_chan *d40c, struct d40_desc *d40d) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 641 | { |
Rabin Vincent | b00f938 | 2011-01-25 11:18:15 +0100 | [diff] [blame] | 642 | if (d40d->lli_pool.dma_addr) |
| 643 | dma_unmap_single(d40c->base->dev, d40d->lli_pool.dma_addr, |
| 644 | d40d->lli_pool.size, DMA_TO_DEVICE); |
| 645 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 646 | kfree(d40d->lli_pool.base); |
| 647 | d40d->lli_pool.base = NULL; |
| 648 | d40d->lli_pool.size = 0; |
| 649 | d40d->lli_log.src = NULL; |
| 650 | d40d->lli_log.dst = NULL; |
| 651 | d40d->lli_phy.src = NULL; |
| 652 | d40d->lli_phy.dst = NULL; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 653 | } |
| 654 | |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 655 | static int d40_lcla_alloc_one(struct d40_chan *d40c, |
| 656 | struct d40_desc *d40d) |
| 657 | { |
| 658 | unsigned long flags; |
| 659 | int i; |
| 660 | int ret = -EINVAL; |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 661 | |
| 662 | spin_lock_irqsave(&d40c->base->lcla_pool.lock, flags); |
| 663 | |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 664 | /* |
| 665 | * Allocate both src and dst at the same time, therefore the half |
| 666 | * start on 1 since 0 can't be used since zero is used as end marker. |
| 667 | */ |
| 668 | for (i = 1 ; i < D40_LCLA_LINK_PER_EVENT_GRP / 2; i++) { |
Fabio Baltieri | 7ce529e | 2012-12-18 16:59:09 +0100 | [diff] [blame] | 669 | int idx = d40c->phy_chan->num * D40_LCLA_LINK_PER_EVENT_GRP + i; |
| 670 | |
| 671 | if (!d40c->base->lcla_pool.alloc_map[idx]) { |
| 672 | d40c->base->lcla_pool.alloc_map[idx] = d40d; |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 673 | d40d->lcla_alloc++; |
| 674 | ret = i; |
| 675 | break; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | spin_unlock_irqrestore(&d40c->base->lcla_pool.lock, flags); |
| 680 | |
| 681 | return ret; |
| 682 | } |
| 683 | |
| 684 | static int d40_lcla_free_all(struct d40_chan *d40c, |
| 685 | struct d40_desc *d40d) |
| 686 | { |
| 687 | unsigned long flags; |
| 688 | int i; |
| 689 | int ret = -EINVAL; |
| 690 | |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 691 | if (chan_is_physical(d40c)) |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 692 | return 0; |
| 693 | |
| 694 | spin_lock_irqsave(&d40c->base->lcla_pool.lock, flags); |
| 695 | |
| 696 | for (i = 1 ; i < D40_LCLA_LINK_PER_EVENT_GRP / 2; i++) { |
Fabio Baltieri | 7ce529e | 2012-12-18 16:59:09 +0100 | [diff] [blame] | 697 | int idx = d40c->phy_chan->num * D40_LCLA_LINK_PER_EVENT_GRP + i; |
| 698 | |
| 699 | if (d40c->base->lcla_pool.alloc_map[idx] == d40d) { |
| 700 | d40c->base->lcla_pool.alloc_map[idx] = NULL; |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 701 | d40d->lcla_alloc--; |
| 702 | if (d40d->lcla_alloc == 0) { |
| 703 | ret = 0; |
| 704 | break; |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | spin_unlock_irqrestore(&d40c->base->lcla_pool.lock, flags); |
| 710 | |
| 711 | return ret; |
| 712 | |
| 713 | } |
| 714 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 715 | static void d40_desc_remove(struct d40_desc *d40d) |
| 716 | { |
| 717 | list_del(&d40d->node); |
| 718 | } |
| 719 | |
| 720 | static struct d40_desc *d40_desc_get(struct d40_chan *d40c) |
| 721 | { |
Rabin Vincent | a2c15fa | 2010-10-06 08:20:37 +0000 | [diff] [blame] | 722 | struct d40_desc *desc = NULL; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 723 | |
| 724 | if (!list_empty(&d40c->client)) { |
Rabin Vincent | a2c15fa | 2010-10-06 08:20:37 +0000 | [diff] [blame] | 725 | struct d40_desc *d; |
| 726 | struct d40_desc *_d; |
| 727 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 728 | list_for_each_entry_safe(d, _d, &d40c->client, node) { |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 729 | if (async_tx_test_ack(&d->txd)) { |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 730 | d40_desc_remove(d); |
Rabin Vincent | a2c15fa | 2010-10-06 08:20:37 +0000 | [diff] [blame] | 731 | desc = d; |
| 732 | memset(desc, 0, sizeof(*desc)); |
Jonas Aaberg | c675b1b | 2010-06-20 21:25:08 +0000 | [diff] [blame] | 733 | break; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 734 | } |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 735 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 736 | } |
Rabin Vincent | a2c15fa | 2010-10-06 08:20:37 +0000 | [diff] [blame] | 737 | |
| 738 | if (!desc) |
| 739 | desc = kmem_cache_zalloc(d40c->base->desc_slab, GFP_NOWAIT); |
| 740 | |
| 741 | if (desc) |
| 742 | INIT_LIST_HEAD(&desc->node); |
| 743 | |
| 744 | return desc; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | static void d40_desc_free(struct d40_chan *d40c, struct d40_desc *d40d) |
| 748 | { |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 749 | |
Rabin Vincent | b00f938 | 2011-01-25 11:18:15 +0100 | [diff] [blame] | 750 | d40_pool_lli_free(d40c, d40d); |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 751 | d40_lcla_free_all(d40c, d40d); |
Jonas Aaberg | c675b1b | 2010-06-20 21:25:08 +0000 | [diff] [blame] | 752 | kmem_cache_free(d40c->base->desc_slab, d40d); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | static void d40_desc_submit(struct d40_chan *d40c, struct d40_desc *desc) |
| 756 | { |
| 757 | list_add_tail(&desc->node, &d40c->active); |
| 758 | } |
| 759 | |
Rabin Vincent | 1c4b092 | 2011-01-25 11:18:24 +0100 | [diff] [blame] | 760 | static void d40_phy_lli_load(struct d40_chan *chan, struct d40_desc *desc) |
| 761 | { |
| 762 | struct d40_phy_lli *lli_dst = desc->lli_phy.dst; |
| 763 | struct d40_phy_lli *lli_src = desc->lli_phy.src; |
| 764 | void __iomem *base = chan_base(chan); |
| 765 | |
| 766 | writel(lli_src->reg_cfg, base + D40_CHAN_REG_SSCFG); |
| 767 | writel(lli_src->reg_elt, base + D40_CHAN_REG_SSELT); |
| 768 | writel(lli_src->reg_ptr, base + D40_CHAN_REG_SSPTR); |
| 769 | writel(lli_src->reg_lnk, base + D40_CHAN_REG_SSLNK); |
| 770 | |
| 771 | writel(lli_dst->reg_cfg, base + D40_CHAN_REG_SDCFG); |
| 772 | writel(lli_dst->reg_elt, base + D40_CHAN_REG_SDELT); |
| 773 | writel(lli_dst->reg_ptr, base + D40_CHAN_REG_SDPTR); |
| 774 | writel(lli_dst->reg_lnk, base + D40_CHAN_REG_SDLNK); |
| 775 | } |
| 776 | |
Fabio Baltieri | 4226dd8 | 2012-12-13 13:46:16 +0100 | [diff] [blame] | 777 | static void d40_desc_done(struct d40_chan *d40c, struct d40_desc *desc) |
| 778 | { |
| 779 | list_add_tail(&desc->node, &d40c->done); |
| 780 | } |
| 781 | |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 782 | static void d40_log_lli_to_lcxa(struct d40_chan *chan, struct d40_desc *desc) |
| 783 | { |
| 784 | struct d40_lcla_pool *pool = &chan->base->lcla_pool; |
| 785 | struct d40_log_lli_bidir *lli = &desc->lli_log; |
| 786 | int lli_current = desc->lli_current; |
| 787 | int lli_len = desc->lli_len; |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 788 | bool cyclic = desc->cyclic; |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 789 | int curr_lcla = -EINVAL; |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 790 | int first_lcla = 0; |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 791 | bool use_esram_lcla = chan->base->plat_data->use_esram_lcla; |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 792 | bool linkback; |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 793 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 794 | /* |
| 795 | * We may have partially running cyclic transfers, in case we did't get |
| 796 | * enough LCLA entries. |
| 797 | */ |
| 798 | linkback = cyclic && lli_current == 0; |
| 799 | |
| 800 | /* |
| 801 | * For linkback, we need one LCLA even with only one link, because we |
| 802 | * can't link back to the one in LCPA space |
| 803 | */ |
| 804 | if (linkback || (lli_len - lli_current > 1)) { |
Fabio Baltieri | 7407048 | 2012-12-18 12:25:14 +0100 | [diff] [blame] | 805 | /* |
| 806 | * If the channel is expected to use only soft_lli don't |
| 807 | * allocate a lcla. This is to avoid a HW issue that exists |
| 808 | * in some controller during a peripheral to memory transfer |
| 809 | * that uses linked lists. |
| 810 | */ |
| 811 | if (!(chan->phy_chan->use_soft_lli && |
| 812 | chan->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM)) |
| 813 | curr_lcla = d40_lcla_alloc_one(chan, desc); |
| 814 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 815 | first_lcla = curr_lcla; |
| 816 | } |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 817 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 818 | /* |
| 819 | * For linkback, we normally load the LCPA in the loop since we need to |
| 820 | * link it to the second LCLA and not the first. However, if we |
| 821 | * couldn't even get a first LCLA, then we have to run in LCPA and |
| 822 | * reload manually. |
| 823 | */ |
| 824 | if (!linkback || curr_lcla == -EINVAL) { |
| 825 | unsigned int flags = 0; |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 826 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 827 | if (curr_lcla == -EINVAL) |
| 828 | flags |= LLI_TERM_INT; |
| 829 | |
| 830 | d40_log_lli_lcpa_write(chan->lcpa, |
| 831 | &lli->dst[lli_current], |
| 832 | &lli->src[lli_current], |
| 833 | curr_lcla, |
| 834 | flags); |
| 835 | lli_current++; |
| 836 | } |
Rabin Vincent | 6045f0b | 2011-01-25 11:18:32 +0100 | [diff] [blame] | 837 | |
| 838 | if (curr_lcla < 0) |
| 839 | goto out; |
| 840 | |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 841 | for (; lli_current < lli_len; lli_current++) { |
| 842 | unsigned int lcla_offset = chan->phy_chan->num * 1024 + |
| 843 | 8 * curr_lcla * 2; |
| 844 | struct d40_log_lli *lcla = pool->base + lcla_offset; |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 845 | unsigned int flags = 0; |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 846 | int next_lcla; |
| 847 | |
| 848 | if (lli_current + 1 < lli_len) |
| 849 | next_lcla = d40_lcla_alloc_one(chan, desc); |
| 850 | else |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 851 | next_lcla = linkback ? first_lcla : -EINVAL; |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 852 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 853 | if (cyclic || next_lcla == -EINVAL) |
| 854 | flags |= LLI_TERM_INT; |
| 855 | |
| 856 | if (linkback && curr_lcla == first_lcla) { |
| 857 | /* First link goes in both LCPA and LCLA */ |
| 858 | d40_log_lli_lcpa_write(chan->lcpa, |
| 859 | &lli->dst[lli_current], |
| 860 | &lli->src[lli_current], |
| 861 | next_lcla, flags); |
| 862 | } |
| 863 | |
| 864 | /* |
| 865 | * One unused LCLA in the cyclic case if the very first |
| 866 | * next_lcla fails... |
| 867 | */ |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 868 | d40_log_lli_lcla_write(lcla, |
| 869 | &lli->dst[lli_current], |
| 870 | &lli->src[lli_current], |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 871 | next_lcla, flags); |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 872 | |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 873 | /* |
| 874 | * Cache maintenance is not needed if lcla is |
| 875 | * mapped in esram |
| 876 | */ |
| 877 | if (!use_esram_lcla) { |
| 878 | dma_sync_single_range_for_device(chan->base->dev, |
| 879 | pool->dma_addr, lcla_offset, |
| 880 | 2 * sizeof(struct d40_log_lli), |
| 881 | DMA_TO_DEVICE); |
| 882 | } |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 883 | curr_lcla = next_lcla; |
| 884 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 885 | if (curr_lcla == -EINVAL || curr_lcla == first_lcla) { |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 886 | lli_current++; |
| 887 | break; |
| 888 | } |
| 889 | } |
| 890 | |
Rabin Vincent | 6045f0b | 2011-01-25 11:18:32 +0100 | [diff] [blame] | 891 | out: |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 892 | desc->lli_current = lli_current; |
| 893 | } |
| 894 | |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 895 | static void d40_desc_load(struct d40_chan *d40c, struct d40_desc *d40d) |
| 896 | { |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 897 | if (chan_is_physical(d40c)) { |
Rabin Vincent | 1c4b092 | 2011-01-25 11:18:24 +0100 | [diff] [blame] | 898 | d40_phy_lli_load(d40c, d40d); |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 899 | d40d->lli_current = d40d->lli_len; |
Rabin Vincent | e65889c | 2011-01-25 11:18:31 +0100 | [diff] [blame] | 900 | } else |
| 901 | d40_log_lli_to_lcxa(d40c, d40d); |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 904 | static struct d40_desc *d40_first_active_get(struct d40_chan *d40c) |
| 905 | { |
| 906 | struct d40_desc *d; |
| 907 | |
| 908 | if (list_empty(&d40c->active)) |
| 909 | return NULL; |
| 910 | |
| 911 | d = list_first_entry(&d40c->active, |
| 912 | struct d40_desc, |
| 913 | node); |
| 914 | return d; |
| 915 | } |
| 916 | |
Per Forlin | 7404368 | 2011-08-29 13:33:34 +0200 | [diff] [blame] | 917 | /* remove desc from current queue and add it to the pending_queue */ |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 918 | static void d40_desc_queue(struct d40_chan *d40c, struct d40_desc *desc) |
| 919 | { |
Per Forlin | 7404368 | 2011-08-29 13:33:34 +0200 | [diff] [blame] | 920 | d40_desc_remove(desc); |
| 921 | desc->is_in_client_list = false; |
Per Forlin | a8f3067 | 2011-06-26 23:29:52 +0200 | [diff] [blame] | 922 | list_add_tail(&desc->node, &d40c->pending_queue); |
| 923 | } |
| 924 | |
| 925 | static struct d40_desc *d40_first_pending(struct d40_chan *d40c) |
| 926 | { |
| 927 | struct d40_desc *d; |
| 928 | |
| 929 | if (list_empty(&d40c->pending_queue)) |
| 930 | return NULL; |
| 931 | |
| 932 | d = list_first_entry(&d40c->pending_queue, |
| 933 | struct d40_desc, |
| 934 | node); |
| 935 | return d; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | static struct d40_desc *d40_first_queued(struct d40_chan *d40c) |
| 939 | { |
| 940 | struct d40_desc *d; |
| 941 | |
| 942 | if (list_empty(&d40c->queue)) |
| 943 | return NULL; |
| 944 | |
| 945 | d = list_first_entry(&d40c->queue, |
| 946 | struct d40_desc, |
| 947 | node); |
| 948 | return d; |
| 949 | } |
| 950 | |
Fabio Baltieri | 4226dd8 | 2012-12-13 13:46:16 +0100 | [diff] [blame] | 951 | static struct d40_desc *d40_first_done(struct d40_chan *d40c) |
| 952 | { |
| 953 | if (list_empty(&d40c->done)) |
| 954 | return NULL; |
| 955 | |
| 956 | return list_first_entry(&d40c->done, struct d40_desc, node); |
| 957 | } |
| 958 | |
Per Forlin | d49278e | 2010-12-20 18:31:38 +0100 | [diff] [blame] | 959 | static int d40_psize_2_burst_size(bool is_log, int psize) |
| 960 | { |
| 961 | if (is_log) { |
| 962 | if (psize == STEDMA40_PSIZE_LOG_1) |
| 963 | return 1; |
| 964 | } else { |
| 965 | if (psize == STEDMA40_PSIZE_PHY_1) |
| 966 | return 1; |
| 967 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 968 | |
Per Forlin | d49278e | 2010-12-20 18:31:38 +0100 | [diff] [blame] | 969 | return 2 << psize; |
| 970 | } |
| 971 | |
| 972 | /* |
| 973 | * The dma only supports transmitting packages up to |
| 974 | * STEDMA40_MAX_SEG_SIZE << data_width. Calculate the total number of |
| 975 | * dma elements required to send the entire sg list |
| 976 | */ |
| 977 | static int d40_size_2_dmalen(int size, u32 data_width1, u32 data_width2) |
| 978 | { |
| 979 | int dmalen; |
| 980 | u32 max_w = max(data_width1, data_width2); |
| 981 | u32 min_w = min(data_width1, data_width2); |
| 982 | u32 seg_max = ALIGN(STEDMA40_MAX_SEG_SIZE << min_w, 1 << max_w); |
| 983 | |
| 984 | if (seg_max > STEDMA40_MAX_SEG_SIZE) |
| 985 | seg_max -= (1 << max_w); |
| 986 | |
| 987 | if (!IS_ALIGNED(size, 1 << max_w)) |
| 988 | return -EINVAL; |
| 989 | |
| 990 | if (size <= seg_max) |
| 991 | dmalen = 1; |
| 992 | else { |
| 993 | dmalen = size / seg_max; |
| 994 | if (dmalen * seg_max < size) |
| 995 | dmalen++; |
| 996 | } |
| 997 | return dmalen; |
| 998 | } |
| 999 | |
| 1000 | static int d40_sg_2_dmalen(struct scatterlist *sgl, int sg_len, |
| 1001 | u32 data_width1, u32 data_width2) |
| 1002 | { |
| 1003 | struct scatterlist *sg; |
| 1004 | int i; |
| 1005 | int len = 0; |
| 1006 | int ret; |
| 1007 | |
| 1008 | for_each_sg(sgl, sg, sg_len, i) { |
| 1009 | ret = d40_size_2_dmalen(sg_dma_len(sg), |
| 1010 | data_width1, data_width2); |
| 1011 | if (ret < 0) |
| 1012 | return ret; |
| 1013 | len += ret; |
| 1014 | } |
| 1015 | return len; |
| 1016 | } |
| 1017 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 1018 | |
| 1019 | #ifdef CONFIG_PM |
| 1020 | static void dma40_backup(void __iomem *baseaddr, u32 *backup, |
| 1021 | u32 *regaddr, int num, bool save) |
| 1022 | { |
| 1023 | int i; |
| 1024 | |
| 1025 | for (i = 0; i < num; i++) { |
| 1026 | void __iomem *addr = baseaddr + regaddr[i]; |
| 1027 | |
| 1028 | if (save) |
| 1029 | backup[i] = readl_relaxed(addr); |
| 1030 | else |
| 1031 | writel_relaxed(backup[i], addr); |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | static void d40_save_restore_registers(struct d40_base *base, bool save) |
| 1036 | { |
| 1037 | int i; |
| 1038 | |
| 1039 | /* Save/Restore channel specific registers */ |
| 1040 | for (i = 0; i < base->num_phy_chans; i++) { |
| 1041 | void __iomem *addr; |
| 1042 | int idx; |
| 1043 | |
| 1044 | if (base->phy_res[i].reserved) |
| 1045 | continue; |
| 1046 | |
| 1047 | addr = base->virtbase + D40_DREG_PCBASE + i * D40_DREG_PCDELTA; |
| 1048 | idx = i * ARRAY_SIZE(d40_backup_regs_chan); |
| 1049 | |
| 1050 | dma40_backup(addr, &base->reg_val_backup_chan[idx], |
| 1051 | d40_backup_regs_chan, |
| 1052 | ARRAY_SIZE(d40_backup_regs_chan), |
| 1053 | save); |
| 1054 | } |
| 1055 | |
| 1056 | /* Save/Restore global registers */ |
| 1057 | dma40_backup(base->virtbase, base->reg_val_backup, |
| 1058 | d40_backup_regs, ARRAY_SIZE(d40_backup_regs), |
| 1059 | save); |
| 1060 | |
| 1061 | /* Save/Restore registers only existing on dma40 v3 and later */ |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 1062 | if (base->gen_dmac.backup) |
| 1063 | dma40_backup(base->virtbase, base->reg_val_backup_v4, |
| 1064 | base->gen_dmac.backup, |
| 1065 | base->gen_dmac.backup_size, |
| 1066 | save); |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 1067 | } |
| 1068 | #else |
| 1069 | static void d40_save_restore_registers(struct d40_base *base, bool save) |
| 1070 | { |
| 1071 | } |
| 1072 | #endif |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1073 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1074 | static int __d40_execute_command_phy(struct d40_chan *d40c, |
| 1075 | enum d40_command command) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1076 | { |
Jonas Aaberg | 767a967 | 2010-08-09 12:08:34 +0000 | [diff] [blame] | 1077 | u32 status; |
| 1078 | int i; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1079 | void __iomem *active_reg; |
| 1080 | int ret = 0; |
| 1081 | unsigned long flags; |
Jonas Aaberg | 1d392a7 | 2010-06-20 21:26:01 +0000 | [diff] [blame] | 1082 | u32 wmask; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1083 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1084 | if (command == D40_DMA_STOP) { |
| 1085 | ret = __d40_execute_command_phy(d40c, D40_DMA_SUSPEND_REQ); |
| 1086 | if (ret) |
| 1087 | return ret; |
| 1088 | } |
| 1089 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1090 | spin_lock_irqsave(&d40c->base->execmd_lock, flags); |
| 1091 | |
| 1092 | if (d40c->phy_chan->num % 2 == 0) |
| 1093 | active_reg = d40c->base->virtbase + D40_DREG_ACTIVE; |
| 1094 | else |
| 1095 | active_reg = d40c->base->virtbase + D40_DREG_ACTIVO; |
| 1096 | |
| 1097 | if (command == D40_DMA_SUSPEND_REQ) { |
| 1098 | status = (readl(active_reg) & |
| 1099 | D40_CHAN_POS_MASK(d40c->phy_chan->num)) >> |
| 1100 | D40_CHAN_POS(d40c->phy_chan->num); |
| 1101 | |
| 1102 | if (status == D40_DMA_SUSPENDED || status == D40_DMA_STOP) |
| 1103 | goto done; |
| 1104 | } |
| 1105 | |
Jonas Aaberg | 1d392a7 | 2010-06-20 21:26:01 +0000 | [diff] [blame] | 1106 | wmask = 0xffffffff & ~(D40_CHAN_POS_MASK(d40c->phy_chan->num)); |
| 1107 | writel(wmask | (command << D40_CHAN_POS(d40c->phy_chan->num)), |
| 1108 | active_reg); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1109 | |
| 1110 | if (command == D40_DMA_SUSPEND_REQ) { |
| 1111 | |
| 1112 | for (i = 0 ; i < D40_SUSPEND_MAX_IT; i++) { |
| 1113 | status = (readl(active_reg) & |
| 1114 | D40_CHAN_POS_MASK(d40c->phy_chan->num)) >> |
| 1115 | D40_CHAN_POS(d40c->phy_chan->num); |
| 1116 | |
| 1117 | cpu_relax(); |
| 1118 | /* |
| 1119 | * Reduce the number of bus accesses while |
| 1120 | * waiting for the DMA to suspend. |
| 1121 | */ |
| 1122 | udelay(3); |
| 1123 | |
| 1124 | if (status == D40_DMA_STOP || |
| 1125 | status == D40_DMA_SUSPENDED) |
| 1126 | break; |
| 1127 | } |
| 1128 | |
| 1129 | if (i == D40_SUSPEND_MAX_IT) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 1130 | chan_err(d40c, |
| 1131 | "unable to suspend the chl %d (log: %d) status %x\n", |
| 1132 | d40c->phy_chan->num, d40c->log_num, |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1133 | status); |
| 1134 | dump_stack(); |
| 1135 | ret = -EBUSY; |
| 1136 | } |
| 1137 | |
| 1138 | } |
| 1139 | done: |
| 1140 | spin_unlock_irqrestore(&d40c->base->execmd_lock, flags); |
| 1141 | return ret; |
| 1142 | } |
| 1143 | |
| 1144 | static void d40_term_all(struct d40_chan *d40c) |
| 1145 | { |
| 1146 | struct d40_desc *d40d; |
Per Forlin | 7404368 | 2011-08-29 13:33:34 +0200 | [diff] [blame] | 1147 | struct d40_desc *_d; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1148 | |
Fabio Baltieri | 4226dd8 | 2012-12-13 13:46:16 +0100 | [diff] [blame] | 1149 | /* Release completed descriptors */ |
| 1150 | while ((d40d = d40_first_done(d40c))) { |
| 1151 | d40_desc_remove(d40d); |
| 1152 | d40_desc_free(d40c, d40d); |
| 1153 | } |
| 1154 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1155 | /* Release active descriptors */ |
| 1156 | while ((d40d = d40_first_active_get(d40c))) { |
| 1157 | d40_desc_remove(d40d); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1158 | d40_desc_free(d40c, d40d); |
| 1159 | } |
| 1160 | |
| 1161 | /* Release queued descriptors waiting for transfer */ |
| 1162 | while ((d40d = d40_first_queued(d40c))) { |
| 1163 | d40_desc_remove(d40d); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1164 | d40_desc_free(d40c, d40d); |
| 1165 | } |
| 1166 | |
Per Forlin | a8f3067 | 2011-06-26 23:29:52 +0200 | [diff] [blame] | 1167 | /* Release pending descriptors */ |
| 1168 | while ((d40d = d40_first_pending(d40c))) { |
| 1169 | d40_desc_remove(d40d); |
| 1170 | d40_desc_free(d40c, d40d); |
| 1171 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1172 | |
Per Forlin | 7404368 | 2011-08-29 13:33:34 +0200 | [diff] [blame] | 1173 | /* Release client owned descriptors */ |
| 1174 | if (!list_empty(&d40c->client)) |
| 1175 | list_for_each_entry_safe(d40d, _d, &d40c->client, node) { |
| 1176 | d40_desc_remove(d40d); |
| 1177 | d40_desc_free(d40c, d40d); |
| 1178 | } |
| 1179 | |
Per Forlin | 82babbb36 | 2011-08-29 13:33:35 +0200 | [diff] [blame] | 1180 | /* Release descriptors in prepare queue */ |
| 1181 | if (!list_empty(&d40c->prepare_queue)) |
| 1182 | list_for_each_entry_safe(d40d, _d, |
| 1183 | &d40c->prepare_queue, node) { |
| 1184 | d40_desc_remove(d40d); |
| 1185 | d40_desc_free(d40c, d40d); |
| 1186 | } |
Per Forlin | 7404368 | 2011-08-29 13:33:34 +0200 | [diff] [blame] | 1187 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1188 | d40c->pending_tx = 0; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1189 | } |
| 1190 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1191 | static void __d40_config_set_event(struct d40_chan *d40c, |
| 1192 | enum d40_events event_type, u32 event, |
| 1193 | int reg) |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1194 | { |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 1195 | void __iomem *addr = chan_base(d40c) + reg; |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1196 | int tries; |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1197 | u32 status; |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1198 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1199 | switch (event_type) { |
| 1200 | |
| 1201 | case D40_DEACTIVATE_EVENTLINE: |
| 1202 | |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1203 | writel((D40_DEACTIVATE_EVENTLINE << D40_EVENTLINE_POS(event)) |
| 1204 | | ~D40_EVENTLINE_MASK(event), addr); |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1205 | break; |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1206 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1207 | case D40_SUSPEND_REQ_EVENTLINE: |
| 1208 | status = (readl(addr) & D40_EVENTLINE_MASK(event)) >> |
| 1209 | D40_EVENTLINE_POS(event); |
| 1210 | |
| 1211 | if (status == D40_DEACTIVATE_EVENTLINE || |
| 1212 | status == D40_SUSPEND_REQ_EVENTLINE) |
| 1213 | break; |
| 1214 | |
| 1215 | writel((D40_SUSPEND_REQ_EVENTLINE << D40_EVENTLINE_POS(event)) |
| 1216 | | ~D40_EVENTLINE_MASK(event), addr); |
| 1217 | |
| 1218 | for (tries = 0 ; tries < D40_SUSPEND_MAX_IT; tries++) { |
| 1219 | |
| 1220 | status = (readl(addr) & D40_EVENTLINE_MASK(event)) >> |
| 1221 | D40_EVENTLINE_POS(event); |
| 1222 | |
| 1223 | cpu_relax(); |
| 1224 | /* |
| 1225 | * Reduce the number of bus accesses while |
| 1226 | * waiting for the DMA to suspend. |
| 1227 | */ |
| 1228 | udelay(3); |
| 1229 | |
| 1230 | if (status == D40_DEACTIVATE_EVENTLINE) |
| 1231 | break; |
| 1232 | } |
| 1233 | |
| 1234 | if (tries == D40_SUSPEND_MAX_IT) { |
| 1235 | chan_err(d40c, |
| 1236 | "unable to stop the event_line chl %d (log: %d)" |
| 1237 | "status %x\n", d40c->phy_chan->num, |
| 1238 | d40c->log_num, status); |
| 1239 | } |
| 1240 | break; |
| 1241 | |
| 1242 | case D40_ACTIVATE_EVENTLINE: |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1243 | /* |
| 1244 | * The hardware sometimes doesn't register the enable when src and dst |
| 1245 | * event lines are active on the same logical channel. Retry to ensure |
| 1246 | * it does. Usually only one retry is sufficient. |
| 1247 | */ |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1248 | tries = 100; |
| 1249 | while (--tries) { |
| 1250 | writel((D40_ACTIVATE_EVENTLINE << |
| 1251 | D40_EVENTLINE_POS(event)) | |
| 1252 | ~D40_EVENTLINE_MASK(event), addr); |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1253 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1254 | if (readl(addr) & D40_EVENTLINE_MASK(event)) |
| 1255 | break; |
| 1256 | } |
| 1257 | |
| 1258 | if (tries != 99) |
| 1259 | dev_dbg(chan2dev(d40c), |
| 1260 | "[%s] workaround enable S%cLNK (%d tries)\n", |
| 1261 | __func__, reg == D40_CHAN_REG_SSLNK ? 'S' : 'D', |
| 1262 | 100 - tries); |
| 1263 | |
| 1264 | WARN_ON(!tries); |
| 1265 | break; |
| 1266 | |
| 1267 | case D40_ROUND_EVENTLINE: |
| 1268 | BUG(); |
| 1269 | break; |
| 1270 | |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1271 | } |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1272 | } |
| 1273 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1274 | static void d40_config_set_event(struct d40_chan *d40c, |
| 1275 | enum d40_events event_type) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1276 | { |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1277 | /* Enable event line connected to device (or memcpy) */ |
| 1278 | if ((d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) || |
| 1279 | (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_PERIPH)) { |
| 1280 | u32 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type); |
| 1281 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1282 | __d40_config_set_event(d40c, event_type, event, |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1283 | D40_CHAN_REG_SSLNK); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1284 | } |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1285 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1286 | if (d40c->dma_cfg.dir != STEDMA40_PERIPH_TO_MEM) { |
| 1287 | u32 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type); |
| 1288 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1289 | __d40_config_set_event(d40c, event_type, event, |
Rabin Vincent | 262d291 | 2011-01-25 11:18:05 +0100 | [diff] [blame] | 1290 | D40_CHAN_REG_SDLNK); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1291 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1292 | } |
| 1293 | |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 1294 | static u32 d40_chan_has_events(struct d40_chan *d40c) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1295 | { |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 1296 | void __iomem *chanbase = chan_base(d40c); |
Jonas Aaberg | be8cb7d | 2010-08-09 12:07:44 +0000 | [diff] [blame] | 1297 | u32 val; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1298 | |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 1299 | val = readl(chanbase + D40_CHAN_REG_SSLNK); |
| 1300 | val |= readl(chanbase + D40_CHAN_REG_SDLNK); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1301 | |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 1302 | return val; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1303 | } |
| 1304 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1305 | static int |
| 1306 | __d40_execute_command_log(struct d40_chan *d40c, enum d40_command command) |
| 1307 | { |
| 1308 | unsigned long flags; |
| 1309 | int ret = 0; |
| 1310 | u32 active_status; |
| 1311 | void __iomem *active_reg; |
| 1312 | |
| 1313 | if (d40c->phy_chan->num % 2 == 0) |
| 1314 | active_reg = d40c->base->virtbase + D40_DREG_ACTIVE; |
| 1315 | else |
| 1316 | active_reg = d40c->base->virtbase + D40_DREG_ACTIVO; |
| 1317 | |
| 1318 | |
| 1319 | spin_lock_irqsave(&d40c->phy_chan->lock, flags); |
| 1320 | |
| 1321 | switch (command) { |
| 1322 | case D40_DMA_STOP: |
| 1323 | case D40_DMA_SUSPEND_REQ: |
| 1324 | |
| 1325 | active_status = (readl(active_reg) & |
| 1326 | D40_CHAN_POS_MASK(d40c->phy_chan->num)) >> |
| 1327 | D40_CHAN_POS(d40c->phy_chan->num); |
| 1328 | |
| 1329 | if (active_status == D40_DMA_RUN) |
| 1330 | d40_config_set_event(d40c, D40_SUSPEND_REQ_EVENTLINE); |
| 1331 | else |
| 1332 | d40_config_set_event(d40c, D40_DEACTIVATE_EVENTLINE); |
| 1333 | |
| 1334 | if (!d40_chan_has_events(d40c) && (command == D40_DMA_STOP)) |
| 1335 | ret = __d40_execute_command_phy(d40c, command); |
| 1336 | |
| 1337 | break; |
| 1338 | |
| 1339 | case D40_DMA_RUN: |
| 1340 | |
| 1341 | d40_config_set_event(d40c, D40_ACTIVATE_EVENTLINE); |
| 1342 | ret = __d40_execute_command_phy(d40c, command); |
| 1343 | break; |
| 1344 | |
| 1345 | case D40_DMA_SUSPENDED: |
| 1346 | BUG(); |
| 1347 | break; |
| 1348 | } |
| 1349 | |
| 1350 | spin_unlock_irqrestore(&d40c->phy_chan->lock, flags); |
| 1351 | return ret; |
| 1352 | } |
| 1353 | |
| 1354 | static int d40_channel_execute_command(struct d40_chan *d40c, |
| 1355 | enum d40_command command) |
| 1356 | { |
| 1357 | if (chan_is_logical(d40c)) |
| 1358 | return __d40_execute_command_log(d40c, command); |
| 1359 | else |
| 1360 | return __d40_execute_command_phy(d40c, command); |
| 1361 | } |
| 1362 | |
Rabin Vincent | 20a5b6d | 2010-10-12 13:00:52 +0000 | [diff] [blame] | 1363 | static u32 d40_get_prmo(struct d40_chan *d40c) |
| 1364 | { |
| 1365 | static const unsigned int phy_map[] = { |
| 1366 | [STEDMA40_PCHAN_BASIC_MODE] |
| 1367 | = D40_DREG_PRMO_PCHAN_BASIC, |
| 1368 | [STEDMA40_PCHAN_MODULO_MODE] |
| 1369 | = D40_DREG_PRMO_PCHAN_MODULO, |
| 1370 | [STEDMA40_PCHAN_DOUBLE_DST_MODE] |
| 1371 | = D40_DREG_PRMO_PCHAN_DOUBLE_DST, |
| 1372 | }; |
| 1373 | static const unsigned int log_map[] = { |
| 1374 | [STEDMA40_LCHAN_SRC_PHY_DST_LOG] |
| 1375 | = D40_DREG_PRMO_LCHAN_SRC_PHY_DST_LOG, |
| 1376 | [STEDMA40_LCHAN_SRC_LOG_DST_PHY] |
| 1377 | = D40_DREG_PRMO_LCHAN_SRC_LOG_DST_PHY, |
| 1378 | [STEDMA40_LCHAN_SRC_LOG_DST_LOG] |
| 1379 | = D40_DREG_PRMO_LCHAN_SRC_LOG_DST_LOG, |
| 1380 | }; |
| 1381 | |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 1382 | if (chan_is_physical(d40c)) |
Rabin Vincent | 20a5b6d | 2010-10-12 13:00:52 +0000 | [diff] [blame] | 1383 | return phy_map[d40c->dma_cfg.mode_opt]; |
| 1384 | else |
| 1385 | return log_map[d40c->dma_cfg.mode_opt]; |
| 1386 | } |
| 1387 | |
Jonas Aaberg | b55912c | 2010-08-09 12:08:02 +0000 | [diff] [blame] | 1388 | static void d40_config_write(struct d40_chan *d40c) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1389 | { |
| 1390 | u32 addr_base; |
| 1391 | u32 var; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1392 | |
| 1393 | /* Odd addresses are even addresses + 4 */ |
| 1394 | addr_base = (d40c->phy_chan->num % 2) * 4; |
| 1395 | /* Setup channel mode to logical or physical */ |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 1396 | var = ((u32)(chan_is_logical(d40c)) + 1) << |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1397 | D40_CHAN_POS(d40c->phy_chan->num); |
| 1398 | writel(var, d40c->base->virtbase + D40_DREG_PRMSE + addr_base); |
| 1399 | |
| 1400 | /* Setup operational mode option register */ |
Rabin Vincent | 20a5b6d | 2010-10-12 13:00:52 +0000 | [diff] [blame] | 1401 | var = d40_get_prmo(d40c) << D40_CHAN_POS(d40c->phy_chan->num); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1402 | |
| 1403 | writel(var, d40c->base->virtbase + D40_DREG_PRMOE + addr_base); |
| 1404 | |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 1405 | if (chan_is_logical(d40c)) { |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 1406 | int lidx = (d40c->phy_chan->num << D40_SREG_ELEM_LOG_LIDX_POS) |
| 1407 | & D40_SREG_ELEM_LOG_LIDX_MASK; |
| 1408 | void __iomem *chanbase = chan_base(d40c); |
| 1409 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1410 | /* Set default config for CFG reg */ |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 1411 | writel(d40c->src_def_cfg, chanbase + D40_CHAN_REG_SSCFG); |
| 1412 | writel(d40c->dst_def_cfg, chanbase + D40_CHAN_REG_SDCFG); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1413 | |
Jonas Aaberg | b55912c | 2010-08-09 12:08:02 +0000 | [diff] [blame] | 1414 | /* Set LIDX for lcla */ |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 1415 | writel(lidx, chanbase + D40_CHAN_REG_SSELT); |
| 1416 | writel(lidx, chanbase + D40_CHAN_REG_SDELT); |
Rabin Vincent | e9f3a49 | 2011-12-28 11:27:40 +0530 | [diff] [blame] | 1417 | |
| 1418 | /* Clear LNK which will be used by d40_chan_has_events() */ |
| 1419 | writel(0, chanbase + D40_CHAN_REG_SSLNK); |
| 1420 | writel(0, chanbase + D40_CHAN_REG_SDLNK); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1421 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1422 | } |
| 1423 | |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1424 | static u32 d40_residue(struct d40_chan *d40c) |
| 1425 | { |
| 1426 | u32 num_elt; |
| 1427 | |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 1428 | if (chan_is_logical(d40c)) |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1429 | num_elt = (readl(&d40c->lcpa->lcsp2) & D40_MEM_LCSP2_ECNT_MASK) |
| 1430 | >> D40_MEM_LCSP2_ECNT_POS; |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 1431 | else { |
| 1432 | u32 val = readl(chan_base(d40c) + D40_CHAN_REG_SDELT); |
| 1433 | num_elt = (val & D40_SREG_ELEM_PHY_ECNT_MASK) |
| 1434 | >> D40_SREG_ELEM_PHY_ECNT_POS; |
| 1435 | } |
| 1436 | |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1437 | return num_elt * (1 << d40c->dma_cfg.dst_info.data_width); |
| 1438 | } |
| 1439 | |
| 1440 | static bool d40_tx_is_linked(struct d40_chan *d40c) |
| 1441 | { |
| 1442 | bool is_link; |
| 1443 | |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 1444 | if (chan_is_logical(d40c)) |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1445 | is_link = readl(&d40c->lcpa->lcsp3) & D40_MEM_LCSP3_DLOS_MASK; |
| 1446 | else |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 1447 | is_link = readl(chan_base(d40c) + D40_CHAN_REG_SDLNK) |
| 1448 | & D40_SREG_LNK_PHYS_LNK_MASK; |
| 1449 | |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1450 | return is_link; |
| 1451 | } |
| 1452 | |
Rabin Vincent | 86eb5fb | 2011-01-25 11:18:34 +0100 | [diff] [blame] | 1453 | static int d40_pause(struct d40_chan *d40c) |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1454 | { |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1455 | int res = 0; |
| 1456 | unsigned long flags; |
| 1457 | |
Jonas Aaberg | 3ac012a | 2010-08-09 12:09:12 +0000 | [diff] [blame] | 1458 | if (!d40c->busy) |
| 1459 | return 0; |
| 1460 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 1461 | pm_runtime_get_sync(d40c->base->dev); |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1462 | spin_lock_irqsave(&d40c->lock, flags); |
| 1463 | |
| 1464 | res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ); |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1465 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 1466 | pm_runtime_mark_last_busy(d40c->base->dev); |
| 1467 | pm_runtime_put_autosuspend(d40c->base->dev); |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1468 | spin_unlock_irqrestore(&d40c->lock, flags); |
| 1469 | return res; |
| 1470 | } |
| 1471 | |
Rabin Vincent | 86eb5fb | 2011-01-25 11:18:34 +0100 | [diff] [blame] | 1472 | static int d40_resume(struct d40_chan *d40c) |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1473 | { |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1474 | int res = 0; |
| 1475 | unsigned long flags; |
| 1476 | |
Jonas Aaberg | 3ac012a | 2010-08-09 12:09:12 +0000 | [diff] [blame] | 1477 | if (!d40c->busy) |
| 1478 | return 0; |
| 1479 | |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1480 | spin_lock_irqsave(&d40c->lock, flags); |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 1481 | pm_runtime_get_sync(d40c->base->dev); |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1482 | |
| 1483 | /* If bytes left to transfer or linked tx resume job */ |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1484 | if (d40_residue(d40c) || d40_tx_is_linked(d40c)) |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1485 | res = d40_channel_execute_command(d40c, D40_DMA_RUN); |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1486 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 1487 | pm_runtime_mark_last_busy(d40c->base->dev); |
| 1488 | pm_runtime_put_autosuspend(d40c->base->dev); |
Jonas Aaberg | aa182ae | 2010-08-09 12:08:26 +0000 | [diff] [blame] | 1489 | spin_unlock_irqrestore(&d40c->lock, flags); |
| 1490 | return res; |
| 1491 | } |
| 1492 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1493 | static dma_cookie_t d40_tx_submit(struct dma_async_tx_descriptor *tx) |
| 1494 | { |
| 1495 | struct d40_chan *d40c = container_of(tx->chan, |
| 1496 | struct d40_chan, |
| 1497 | chan); |
| 1498 | struct d40_desc *d40d = container_of(tx, struct d40_desc, txd); |
| 1499 | unsigned long flags; |
Russell King - ARM Linux | 884485e | 2012-03-06 22:34:46 +0000 | [diff] [blame] | 1500 | dma_cookie_t cookie; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1501 | |
| 1502 | spin_lock_irqsave(&d40c->lock, flags); |
Russell King - ARM Linux | 884485e | 2012-03-06 22:34:46 +0000 | [diff] [blame] | 1503 | cookie = dma_cookie_assign(tx); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1504 | d40_desc_queue(d40c, d40d); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1505 | spin_unlock_irqrestore(&d40c->lock, flags); |
| 1506 | |
Russell King - ARM Linux | 884485e | 2012-03-06 22:34:46 +0000 | [diff] [blame] | 1507 | return cookie; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | static int d40_start(struct d40_chan *d40c) |
| 1511 | { |
Jonas Aaberg | 0c32269 | 2010-06-20 21:25:46 +0000 | [diff] [blame] | 1512 | return d40_channel_execute_command(d40c, D40_DMA_RUN); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | static struct d40_desc *d40_queue_start(struct d40_chan *d40c) |
| 1516 | { |
| 1517 | struct d40_desc *d40d; |
| 1518 | int err; |
| 1519 | |
| 1520 | /* Start queued jobs, if any */ |
| 1521 | d40d = d40_first_queued(d40c); |
| 1522 | |
| 1523 | if (d40d != NULL) { |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1524 | if (!d40c->busy) { |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 1525 | d40c->busy = true; |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1526 | pm_runtime_get_sync(d40c->base->dev); |
| 1527 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1528 | |
| 1529 | /* Remove from queue */ |
| 1530 | d40_desc_remove(d40d); |
| 1531 | |
| 1532 | /* Add to active queue */ |
| 1533 | d40_desc_submit(d40c, d40d); |
| 1534 | |
Rabin Vincent | 7d83a85 | 2011-01-25 11:18:06 +0100 | [diff] [blame] | 1535 | /* Initiate DMA job */ |
| 1536 | d40_desc_load(d40c, d40d); |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 1537 | |
Rabin Vincent | 7d83a85 | 2011-01-25 11:18:06 +0100 | [diff] [blame] | 1538 | /* Start dma job */ |
| 1539 | err = d40_start(d40c); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1540 | |
Rabin Vincent | 7d83a85 | 2011-01-25 11:18:06 +0100 | [diff] [blame] | 1541 | if (err) |
| 1542 | return NULL; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | return d40d; |
| 1546 | } |
| 1547 | |
| 1548 | /* called from interrupt context */ |
| 1549 | static void dma_tc_handle(struct d40_chan *d40c) |
| 1550 | { |
| 1551 | struct d40_desc *d40d; |
| 1552 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1553 | /* Get first active entry from list */ |
| 1554 | d40d = d40_first_active_get(d40c); |
| 1555 | |
| 1556 | if (d40d == NULL) |
| 1557 | return; |
| 1558 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 1559 | if (d40d->cyclic) { |
| 1560 | /* |
| 1561 | * If this was a paritially loaded list, we need to reloaded |
| 1562 | * it, and only when the list is completed. We need to check |
| 1563 | * for done because the interrupt will hit for every link, and |
| 1564 | * not just the last one. |
| 1565 | */ |
| 1566 | if (d40d->lli_current < d40d->lli_len |
| 1567 | && !d40_tx_is_linked(d40c) |
| 1568 | && !d40_residue(d40c)) { |
| 1569 | d40_lcla_free_all(d40c, d40d); |
| 1570 | d40_desc_load(d40c, d40d); |
| 1571 | (void) d40_start(d40c); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1572 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 1573 | if (d40d->lli_current == d40d->lli_len) |
| 1574 | d40d->lli_current = 0; |
| 1575 | } |
| 1576 | } else { |
| 1577 | d40_lcla_free_all(d40c, d40d); |
| 1578 | |
| 1579 | if (d40d->lli_current < d40d->lli_len) { |
| 1580 | d40_desc_load(d40c, d40d); |
| 1581 | /* Start dma job */ |
| 1582 | (void) d40_start(d40c); |
| 1583 | return; |
| 1584 | } |
| 1585 | |
| 1586 | if (d40_queue_start(d40c) == NULL) |
| 1587 | d40c->busy = false; |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 1588 | pm_runtime_mark_last_busy(d40c->base->dev); |
| 1589 | pm_runtime_put_autosuspend(d40c->base->dev); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1590 | |
Fabio Baltieri | 7dd1452 | 2013-02-14 10:03:10 +0100 | [diff] [blame] | 1591 | d40_desc_remove(d40d); |
| 1592 | d40_desc_done(d40c, d40d); |
| 1593 | } |
Fabio Baltieri | 4226dd8 | 2012-12-13 13:46:16 +0100 | [diff] [blame] | 1594 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1595 | d40c->pending_tx++; |
| 1596 | tasklet_schedule(&d40c->tasklet); |
| 1597 | |
| 1598 | } |
| 1599 | |
| 1600 | static void dma_tasklet(unsigned long data) |
| 1601 | { |
| 1602 | struct d40_chan *d40c = (struct d40_chan *) data; |
Jonas Aaberg | 767a967 | 2010-08-09 12:08:34 +0000 | [diff] [blame] | 1603 | struct d40_desc *d40d; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1604 | unsigned long flags; |
| 1605 | dma_async_tx_callback callback; |
| 1606 | void *callback_param; |
| 1607 | |
| 1608 | spin_lock_irqsave(&d40c->lock, flags); |
| 1609 | |
Fabio Baltieri | 4226dd8 | 2012-12-13 13:46:16 +0100 | [diff] [blame] | 1610 | /* Get first entry from the done list */ |
| 1611 | d40d = d40_first_done(d40c); |
| 1612 | if (d40d == NULL) { |
| 1613 | /* Check if we have reached here for cyclic job */ |
| 1614 | d40d = d40_first_active_get(d40c); |
| 1615 | if (d40d == NULL || !d40d->cyclic) |
| 1616 | goto err; |
| 1617 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1618 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 1619 | if (!d40d->cyclic) |
Russell King - ARM Linux | f7fbce0 | 2012-03-06 22:35:07 +0000 | [diff] [blame] | 1620 | dma_cookie_complete(&d40d->txd); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1621 | |
| 1622 | /* |
| 1623 | * If terminating a channel pending_tx is set to zero. |
| 1624 | * This prevents any finished active jobs to return to the client. |
| 1625 | */ |
| 1626 | if (d40c->pending_tx == 0) { |
| 1627 | spin_unlock_irqrestore(&d40c->lock, flags); |
| 1628 | return; |
| 1629 | } |
| 1630 | |
| 1631 | /* Callback to client */ |
Jonas Aaberg | 767a967 | 2010-08-09 12:08:34 +0000 | [diff] [blame] | 1632 | callback = d40d->txd.callback; |
| 1633 | callback_param = d40d->txd.callback_param; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1634 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 1635 | if (!d40d->cyclic) { |
| 1636 | if (async_tx_test_ack(&d40d->txd)) { |
Jonas Aaberg | 767a967 | 2010-08-09 12:08:34 +0000 | [diff] [blame] | 1637 | d40_desc_remove(d40d); |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 1638 | d40_desc_free(d40c, d40d); |
Fabio Baltieri | f26e03a | 2012-12-13 17:12:37 +0100 | [diff] [blame] | 1639 | } else if (!d40d->is_in_client_list) { |
| 1640 | d40_desc_remove(d40d); |
| 1641 | d40_lcla_free_all(d40c, d40d); |
| 1642 | list_add_tail(&d40d->node, &d40c->client); |
| 1643 | d40d->is_in_client_list = true; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | d40c->pending_tx--; |
| 1648 | |
| 1649 | if (d40c->pending_tx) |
| 1650 | tasklet_schedule(&d40c->tasklet); |
| 1651 | |
| 1652 | spin_unlock_irqrestore(&d40c->lock, flags); |
| 1653 | |
Jonas Aaberg | 767a967 | 2010-08-09 12:08:34 +0000 | [diff] [blame] | 1654 | if (callback && (d40d->txd.flags & DMA_PREP_INTERRUPT)) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1655 | callback(callback_param); |
| 1656 | |
| 1657 | return; |
| 1658 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 1659 | err: |
| 1660 | /* Rescue manouver if receiving double interrupts */ |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1661 | if (d40c->pending_tx > 0) |
| 1662 | d40c->pending_tx--; |
| 1663 | spin_unlock_irqrestore(&d40c->lock, flags); |
| 1664 | } |
| 1665 | |
| 1666 | static irqreturn_t d40_handle_interrupt(int irq, void *data) |
| 1667 | { |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1668 | int i; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1669 | u32 idx; |
| 1670 | u32 row; |
| 1671 | long chan = -1; |
| 1672 | struct d40_chan *d40c; |
| 1673 | unsigned long flags; |
| 1674 | struct d40_base *base = data; |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 1675 | u32 regs[base->gen_dmac.il_size]; |
| 1676 | struct d40_interrupt_lookup *il = base->gen_dmac.il; |
| 1677 | u32 il_size = base->gen_dmac.il_size; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1678 | |
| 1679 | spin_lock_irqsave(&base->interrupt_lock, flags); |
| 1680 | |
| 1681 | /* Read interrupt status of both logical and physical channels */ |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 1682 | for (i = 0; i < il_size; i++) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1683 | regs[i] = readl(base->virtbase + il[i].src); |
| 1684 | |
| 1685 | for (;;) { |
| 1686 | |
| 1687 | chan = find_next_bit((unsigned long *)regs, |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 1688 | BITS_PER_LONG * il_size, chan + 1); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1689 | |
| 1690 | /* No more set bits found? */ |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 1691 | if (chan == BITS_PER_LONG * il_size) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1692 | break; |
| 1693 | |
| 1694 | row = chan / BITS_PER_LONG; |
| 1695 | idx = chan & (BITS_PER_LONG - 1); |
| 1696 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1697 | if (il[row].offset == D40_PHY_CHAN) |
| 1698 | d40c = base->lookup_phy_chans[idx]; |
| 1699 | else |
| 1700 | d40c = base->lookup_log_chans[il[row].offset + idx]; |
Fabio Baltieri | 53d6d68 | 2012-12-19 14:41:56 +0100 | [diff] [blame] | 1701 | |
| 1702 | if (!d40c) { |
| 1703 | /* |
| 1704 | * No error because this can happen if something else |
| 1705 | * in the system is using the channel. |
| 1706 | */ |
| 1707 | continue; |
| 1708 | } |
| 1709 | |
| 1710 | /* ACK interrupt */ |
| 1711 | writel(1 << idx, base->virtbase + il[row].clr); |
| 1712 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1713 | spin_lock(&d40c->lock); |
| 1714 | |
| 1715 | if (!il[row].is_error) |
| 1716 | dma_tc_handle(d40c); |
| 1717 | else |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 1718 | d40_err(base->dev, "IRQ chan: %ld offset %d idx %d\n", |
| 1719 | chan, il[row].offset, idx); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1720 | |
| 1721 | spin_unlock(&d40c->lock); |
| 1722 | } |
| 1723 | |
| 1724 | spin_unlock_irqrestore(&base->interrupt_lock, flags); |
| 1725 | |
| 1726 | return IRQ_HANDLED; |
| 1727 | } |
| 1728 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1729 | static int d40_validate_conf(struct d40_chan *d40c, |
| 1730 | struct stedma40_chan_cfg *conf) |
| 1731 | { |
| 1732 | int res = 0; |
| 1733 | u32 dst_event_group = D40_TYPE_TO_GROUP(conf->dst_dev_type); |
| 1734 | u32 src_event_group = D40_TYPE_TO_GROUP(conf->src_dev_type); |
Rabin Vincent | 38bdbf0 | 2010-10-12 13:00:51 +0000 | [diff] [blame] | 1735 | bool is_log = conf->mode == STEDMA40_MODE_LOGICAL; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1736 | |
Linus Walleij | 0747c7ba | 2010-08-09 12:07:36 +0000 | [diff] [blame] | 1737 | if (!conf->dir) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 1738 | chan_err(d40c, "Invalid direction.\n"); |
Linus Walleij | 0747c7ba | 2010-08-09 12:07:36 +0000 | [diff] [blame] | 1739 | res = -EINVAL; |
| 1740 | } |
| 1741 | |
| 1742 | if (conf->dst_dev_type != STEDMA40_DEV_DST_MEMORY && |
| 1743 | d40c->base->plat_data->dev_tx[conf->dst_dev_type] == 0 && |
| 1744 | d40c->runtime_addr == 0) { |
| 1745 | |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 1746 | chan_err(d40c, "Invalid TX channel address (%d)\n", |
| 1747 | conf->dst_dev_type); |
Linus Walleij | 0747c7ba | 2010-08-09 12:07:36 +0000 | [diff] [blame] | 1748 | res = -EINVAL; |
| 1749 | } |
| 1750 | |
| 1751 | if (conf->src_dev_type != STEDMA40_DEV_SRC_MEMORY && |
| 1752 | d40c->base->plat_data->dev_rx[conf->src_dev_type] == 0 && |
| 1753 | d40c->runtime_addr == 0) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 1754 | chan_err(d40c, "Invalid RX channel address (%d)\n", |
| 1755 | conf->src_dev_type); |
Linus Walleij | 0747c7ba | 2010-08-09 12:07:36 +0000 | [diff] [blame] | 1756 | res = -EINVAL; |
| 1757 | } |
| 1758 | |
| 1759 | if (conf->dir == STEDMA40_MEM_TO_PERIPH && |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1760 | dst_event_group == STEDMA40_DEV_DST_MEMORY) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 1761 | chan_err(d40c, "Invalid dst\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1762 | res = -EINVAL; |
| 1763 | } |
| 1764 | |
Linus Walleij | 0747c7ba | 2010-08-09 12:07:36 +0000 | [diff] [blame] | 1765 | if (conf->dir == STEDMA40_PERIPH_TO_MEM && |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1766 | src_event_group == STEDMA40_DEV_SRC_MEMORY) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 1767 | chan_err(d40c, "Invalid src\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1768 | res = -EINVAL; |
| 1769 | } |
| 1770 | |
| 1771 | if (src_event_group == STEDMA40_DEV_SRC_MEMORY && |
| 1772 | dst_event_group == STEDMA40_DEV_DST_MEMORY && is_log) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 1773 | chan_err(d40c, "No event line\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1774 | res = -EINVAL; |
| 1775 | } |
| 1776 | |
| 1777 | if (conf->dir == STEDMA40_PERIPH_TO_PERIPH && |
| 1778 | (src_event_group != dst_event_group)) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 1779 | chan_err(d40c, "Invalid event group\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1780 | res = -EINVAL; |
| 1781 | } |
| 1782 | |
| 1783 | if (conf->dir == STEDMA40_PERIPH_TO_PERIPH) { |
| 1784 | /* |
| 1785 | * DMAC HW supports it. Will be added to this driver, |
| 1786 | * in case any dma client requires it. |
| 1787 | */ |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 1788 | chan_err(d40c, "periph to periph not supported\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1789 | res = -EINVAL; |
| 1790 | } |
| 1791 | |
Per Forlin | d49278e | 2010-12-20 18:31:38 +0100 | [diff] [blame] | 1792 | if (d40_psize_2_burst_size(is_log, conf->src_info.psize) * |
| 1793 | (1 << conf->src_info.data_width) != |
| 1794 | d40_psize_2_burst_size(is_log, conf->dst_info.psize) * |
| 1795 | (1 << conf->dst_info.data_width)) { |
| 1796 | /* |
| 1797 | * The DMAC hardware only supports |
| 1798 | * src (burst x width) == dst (burst x width) |
| 1799 | */ |
| 1800 | |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 1801 | chan_err(d40c, "src (burst x width) != dst (burst x width)\n"); |
Per Forlin | d49278e | 2010-12-20 18:31:38 +0100 | [diff] [blame] | 1802 | res = -EINVAL; |
| 1803 | } |
| 1804 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1805 | return res; |
| 1806 | } |
| 1807 | |
Narayanan G | 5cd326f | 2011-11-30 19:20:42 +0530 | [diff] [blame] | 1808 | static bool d40_alloc_mask_set(struct d40_phy_res *phy, |
| 1809 | bool is_src, int log_event_line, bool is_log, |
| 1810 | bool *first_user) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1811 | { |
| 1812 | unsigned long flags; |
| 1813 | spin_lock_irqsave(&phy->lock, flags); |
Narayanan G | 5cd326f | 2011-11-30 19:20:42 +0530 | [diff] [blame] | 1814 | |
| 1815 | *first_user = ((phy->allocated_src | phy->allocated_dst) |
| 1816 | == D40_ALLOC_FREE); |
| 1817 | |
Marcin Mielczarczyk | 4aed79b | 2010-05-18 00:41:21 +0200 | [diff] [blame] | 1818 | if (!is_log) { |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1819 | /* Physical interrupts are masked per physical full channel */ |
| 1820 | if (phy->allocated_src == D40_ALLOC_FREE && |
| 1821 | phy->allocated_dst == D40_ALLOC_FREE) { |
| 1822 | phy->allocated_dst = D40_ALLOC_PHY; |
| 1823 | phy->allocated_src = D40_ALLOC_PHY; |
| 1824 | goto found; |
| 1825 | } else |
| 1826 | goto not_found; |
| 1827 | } |
| 1828 | |
| 1829 | /* Logical channel */ |
| 1830 | if (is_src) { |
| 1831 | if (phy->allocated_src == D40_ALLOC_PHY) |
| 1832 | goto not_found; |
| 1833 | |
| 1834 | if (phy->allocated_src == D40_ALLOC_FREE) |
| 1835 | phy->allocated_src = D40_ALLOC_LOG_FREE; |
| 1836 | |
| 1837 | if (!(phy->allocated_src & (1 << log_event_line))) { |
| 1838 | phy->allocated_src |= 1 << log_event_line; |
| 1839 | goto found; |
| 1840 | } else |
| 1841 | goto not_found; |
| 1842 | } else { |
| 1843 | if (phy->allocated_dst == D40_ALLOC_PHY) |
| 1844 | goto not_found; |
| 1845 | |
| 1846 | if (phy->allocated_dst == D40_ALLOC_FREE) |
| 1847 | phy->allocated_dst = D40_ALLOC_LOG_FREE; |
| 1848 | |
| 1849 | if (!(phy->allocated_dst & (1 << log_event_line))) { |
| 1850 | phy->allocated_dst |= 1 << log_event_line; |
| 1851 | goto found; |
| 1852 | } else |
| 1853 | goto not_found; |
| 1854 | } |
| 1855 | |
| 1856 | not_found: |
| 1857 | spin_unlock_irqrestore(&phy->lock, flags); |
| 1858 | return false; |
| 1859 | found: |
| 1860 | spin_unlock_irqrestore(&phy->lock, flags); |
| 1861 | return true; |
| 1862 | } |
| 1863 | |
| 1864 | static bool d40_alloc_mask_free(struct d40_phy_res *phy, bool is_src, |
| 1865 | int log_event_line) |
| 1866 | { |
| 1867 | unsigned long flags; |
| 1868 | bool is_free = false; |
| 1869 | |
| 1870 | spin_lock_irqsave(&phy->lock, flags); |
| 1871 | if (!log_event_line) { |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1872 | phy->allocated_dst = D40_ALLOC_FREE; |
| 1873 | phy->allocated_src = D40_ALLOC_FREE; |
| 1874 | is_free = true; |
| 1875 | goto out; |
| 1876 | } |
| 1877 | |
| 1878 | /* Logical channel */ |
| 1879 | if (is_src) { |
| 1880 | phy->allocated_src &= ~(1 << log_event_line); |
| 1881 | if (phy->allocated_src == D40_ALLOC_LOG_FREE) |
| 1882 | phy->allocated_src = D40_ALLOC_FREE; |
| 1883 | } else { |
| 1884 | phy->allocated_dst &= ~(1 << log_event_line); |
| 1885 | if (phy->allocated_dst == D40_ALLOC_LOG_FREE) |
| 1886 | phy->allocated_dst = D40_ALLOC_FREE; |
| 1887 | } |
| 1888 | |
| 1889 | is_free = ((phy->allocated_src | phy->allocated_dst) == |
| 1890 | D40_ALLOC_FREE); |
| 1891 | |
| 1892 | out: |
| 1893 | spin_unlock_irqrestore(&phy->lock, flags); |
| 1894 | |
| 1895 | return is_free; |
| 1896 | } |
| 1897 | |
Narayanan G | 5cd326f | 2011-11-30 19:20:42 +0530 | [diff] [blame] | 1898 | static int d40_allocate_channel(struct d40_chan *d40c, bool *first_phy_user) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1899 | { |
| 1900 | int dev_type; |
| 1901 | int event_group; |
| 1902 | int event_line; |
| 1903 | struct d40_phy_res *phys; |
| 1904 | int i; |
| 1905 | int j; |
| 1906 | int log_num; |
Gerald Baeza | f000df8 | 2012-11-08 14:39:07 +0100 | [diff] [blame] | 1907 | int num_phy_chans; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1908 | bool is_src; |
Rabin Vincent | 38bdbf0 | 2010-10-12 13:00:51 +0000 | [diff] [blame] | 1909 | bool is_log = d40c->dma_cfg.mode == STEDMA40_MODE_LOGICAL; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1910 | |
| 1911 | phys = d40c->base->phy_res; |
Gerald Baeza | f000df8 | 2012-11-08 14:39:07 +0100 | [diff] [blame] | 1912 | num_phy_chans = d40c->base->num_phy_chans; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1913 | |
| 1914 | if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) { |
| 1915 | dev_type = d40c->dma_cfg.src_dev_type; |
| 1916 | log_num = 2 * dev_type; |
| 1917 | is_src = true; |
| 1918 | } else if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH || |
| 1919 | d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) { |
| 1920 | /* dst event lines are used for logical memcpy */ |
| 1921 | dev_type = d40c->dma_cfg.dst_dev_type; |
| 1922 | log_num = 2 * dev_type + 1; |
| 1923 | is_src = false; |
| 1924 | } else |
| 1925 | return -EINVAL; |
| 1926 | |
| 1927 | event_group = D40_TYPE_TO_GROUP(dev_type); |
| 1928 | event_line = D40_TYPE_TO_EVENT(dev_type); |
| 1929 | |
| 1930 | if (!is_log) { |
| 1931 | if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) { |
| 1932 | /* Find physical half channel */ |
Gerald Baeza | f000df8 | 2012-11-08 14:39:07 +0100 | [diff] [blame] | 1933 | if (d40c->dma_cfg.use_fixed_channel) { |
| 1934 | i = d40c->dma_cfg.phy_channel; |
Marcin Mielczarczyk | 4aed79b | 2010-05-18 00:41:21 +0200 | [diff] [blame] | 1935 | if (d40_alloc_mask_set(&phys[i], is_src, |
Narayanan G | 5cd326f | 2011-11-30 19:20:42 +0530 | [diff] [blame] | 1936 | 0, is_log, |
| 1937 | first_phy_user)) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1938 | goto found_phy; |
Gerald Baeza | f000df8 | 2012-11-08 14:39:07 +0100 | [diff] [blame] | 1939 | } else { |
| 1940 | for (i = 0; i < num_phy_chans; i++) { |
| 1941 | if (d40_alloc_mask_set(&phys[i], is_src, |
| 1942 | 0, is_log, |
| 1943 | first_phy_user)) |
| 1944 | goto found_phy; |
| 1945 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1946 | } |
| 1947 | } else |
| 1948 | for (j = 0; j < d40c->base->num_phy_chans; j += 8) { |
| 1949 | int phy_num = j + event_group * 2; |
| 1950 | for (i = phy_num; i < phy_num + 2; i++) { |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 1951 | if (d40_alloc_mask_set(&phys[i], |
| 1952 | is_src, |
| 1953 | 0, |
Narayanan G | 5cd326f | 2011-11-30 19:20:42 +0530 | [diff] [blame] | 1954 | is_log, |
| 1955 | first_phy_user)) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1956 | goto found_phy; |
| 1957 | } |
| 1958 | } |
| 1959 | return -EINVAL; |
| 1960 | found_phy: |
| 1961 | d40c->phy_chan = &phys[i]; |
| 1962 | d40c->log_num = D40_PHY_CHAN; |
| 1963 | goto out; |
| 1964 | } |
| 1965 | if (dev_type == -1) |
| 1966 | return -EINVAL; |
| 1967 | |
| 1968 | /* Find logical channel */ |
| 1969 | for (j = 0; j < d40c->base->num_phy_chans; j += 8) { |
| 1970 | int phy_num = j + event_group * 2; |
Narayanan G | 5cd326f | 2011-11-30 19:20:42 +0530 | [diff] [blame] | 1971 | |
| 1972 | if (d40c->dma_cfg.use_fixed_channel) { |
| 1973 | i = d40c->dma_cfg.phy_channel; |
| 1974 | |
| 1975 | if ((i != phy_num) && (i != phy_num + 1)) { |
| 1976 | dev_err(chan2dev(d40c), |
| 1977 | "invalid fixed phy channel %d\n", i); |
| 1978 | return -EINVAL; |
| 1979 | } |
| 1980 | |
| 1981 | if (d40_alloc_mask_set(&phys[i], is_src, event_line, |
| 1982 | is_log, first_phy_user)) |
| 1983 | goto found_log; |
| 1984 | |
| 1985 | dev_err(chan2dev(d40c), |
| 1986 | "could not allocate fixed phy channel %d\n", i); |
| 1987 | return -EINVAL; |
| 1988 | } |
| 1989 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 1990 | /* |
| 1991 | * Spread logical channels across all available physical rather |
| 1992 | * than pack every logical channel at the first available phy |
| 1993 | * channels. |
| 1994 | */ |
| 1995 | if (is_src) { |
| 1996 | for (i = phy_num; i < phy_num + 2; i++) { |
| 1997 | if (d40_alloc_mask_set(&phys[i], is_src, |
Narayanan G | 5cd326f | 2011-11-30 19:20:42 +0530 | [diff] [blame] | 1998 | event_line, is_log, |
| 1999 | first_phy_user)) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2000 | goto found_log; |
| 2001 | } |
| 2002 | } else { |
| 2003 | for (i = phy_num + 1; i >= phy_num; i--) { |
| 2004 | if (d40_alloc_mask_set(&phys[i], is_src, |
Narayanan G | 5cd326f | 2011-11-30 19:20:42 +0530 | [diff] [blame] | 2005 | event_line, is_log, |
| 2006 | first_phy_user)) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2007 | goto found_log; |
| 2008 | } |
| 2009 | } |
| 2010 | } |
| 2011 | return -EINVAL; |
| 2012 | |
| 2013 | found_log: |
| 2014 | d40c->phy_chan = &phys[i]; |
| 2015 | d40c->log_num = log_num; |
| 2016 | out: |
| 2017 | |
| 2018 | if (is_log) |
| 2019 | d40c->base->lookup_log_chans[d40c->log_num] = d40c; |
| 2020 | else |
| 2021 | d40c->base->lookup_phy_chans[d40c->phy_chan->num] = d40c; |
| 2022 | |
| 2023 | return 0; |
| 2024 | |
| 2025 | } |
| 2026 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2027 | static int d40_config_memcpy(struct d40_chan *d40c) |
| 2028 | { |
| 2029 | dma_cap_mask_t cap = d40c->chan.device->cap_mask; |
| 2030 | |
| 2031 | if (dma_has_cap(DMA_MEMCPY, cap) && !dma_has_cap(DMA_SLAVE, cap)) { |
| 2032 | d40c->dma_cfg = *d40c->base->plat_data->memcpy_conf_log; |
| 2033 | d40c->dma_cfg.src_dev_type = STEDMA40_DEV_SRC_MEMORY; |
Lee Jones | 664a57e | 2013-05-03 15:31:53 +0100 | [diff] [blame] | 2034 | d40c->dma_cfg.dst_dev_type = dma40_memcpy_channels[d40c->chan.chan_id]; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2035 | |
| 2036 | } else if (dma_has_cap(DMA_MEMCPY, cap) && |
| 2037 | dma_has_cap(DMA_SLAVE, cap)) { |
| 2038 | d40c->dma_cfg = *d40c->base->plat_data->memcpy_conf_phy; |
| 2039 | } else { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2040 | chan_err(d40c, "No memcpy\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2041 | return -EINVAL; |
| 2042 | } |
| 2043 | |
| 2044 | return 0; |
| 2045 | } |
| 2046 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2047 | static int d40_free_dma(struct d40_chan *d40c) |
| 2048 | { |
| 2049 | |
| 2050 | int res = 0; |
Jonas Aaberg | d181b3a | 2010-06-20 21:26:38 +0000 | [diff] [blame] | 2051 | u32 event; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2052 | struct d40_phy_res *phy = d40c->phy_chan; |
| 2053 | bool is_src; |
| 2054 | |
| 2055 | /* Terminate all queued and active transfers */ |
| 2056 | d40_term_all(d40c); |
| 2057 | |
| 2058 | if (phy == NULL) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2059 | chan_err(d40c, "phy == null\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2060 | return -EINVAL; |
| 2061 | } |
| 2062 | |
| 2063 | if (phy->allocated_src == D40_ALLOC_FREE && |
| 2064 | phy->allocated_dst == D40_ALLOC_FREE) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2065 | chan_err(d40c, "channel already free\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2066 | return -EINVAL; |
| 2067 | } |
| 2068 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2069 | if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH || |
| 2070 | d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) { |
| 2071 | event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2072 | is_src = false; |
| 2073 | } else if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) { |
| 2074 | event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2075 | is_src = true; |
| 2076 | } else { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2077 | chan_err(d40c, "Unknown direction\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2078 | return -EINVAL; |
| 2079 | } |
| 2080 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2081 | pm_runtime_get_sync(d40c->base->dev); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2082 | res = d40_channel_execute_command(d40c, D40_DMA_STOP); |
| 2083 | if (res) { |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 2084 | chan_err(d40c, "stop failed\n"); |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2085 | goto out; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2086 | } |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2087 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 2088 | d40_alloc_mask_free(phy, is_src, chan_is_logical(d40c) ? event : 0); |
| 2089 | |
| 2090 | if (chan_is_logical(d40c)) |
| 2091 | d40c->base->lookup_log_chans[d40c->log_num] = NULL; |
| 2092 | else |
| 2093 | d40c->base->lookup_phy_chans[phy->num] = NULL; |
| 2094 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2095 | if (d40c->busy) { |
| 2096 | pm_runtime_mark_last_busy(d40c->base->dev); |
| 2097 | pm_runtime_put_autosuspend(d40c->base->dev); |
| 2098 | } |
| 2099 | |
| 2100 | d40c->busy = false; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2101 | d40c->phy_chan = NULL; |
Rabin Vincent | ce2ca12 | 2010-10-12 13:00:49 +0000 | [diff] [blame] | 2102 | d40c->configured = false; |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2103 | out: |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2104 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2105 | pm_runtime_mark_last_busy(d40c->base->dev); |
| 2106 | pm_runtime_put_autosuspend(d40c->base->dev); |
| 2107 | return res; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2108 | } |
| 2109 | |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 2110 | static bool d40_is_paused(struct d40_chan *d40c) |
| 2111 | { |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 2112 | void __iomem *chanbase = chan_base(d40c); |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 2113 | bool is_paused = false; |
| 2114 | unsigned long flags; |
| 2115 | void __iomem *active_reg; |
| 2116 | u32 status; |
| 2117 | u32 event; |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 2118 | |
| 2119 | spin_lock_irqsave(&d40c->lock, flags); |
| 2120 | |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 2121 | if (chan_is_physical(d40c)) { |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 2122 | if (d40c->phy_chan->num % 2 == 0) |
| 2123 | active_reg = d40c->base->virtbase + D40_DREG_ACTIVE; |
| 2124 | else |
| 2125 | active_reg = d40c->base->virtbase + D40_DREG_ACTIVO; |
| 2126 | |
| 2127 | status = (readl(active_reg) & |
| 2128 | D40_CHAN_POS_MASK(d40c->phy_chan->num)) >> |
| 2129 | D40_CHAN_POS(d40c->phy_chan->num); |
| 2130 | if (status == D40_DMA_SUSPENDED || status == D40_DMA_STOP) |
| 2131 | is_paused = true; |
| 2132 | |
| 2133 | goto _exit; |
| 2134 | } |
| 2135 | |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 2136 | if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH || |
Jonas Aaberg | 9dbfbd35c | 2010-08-09 12:08:41 +0000 | [diff] [blame] | 2137 | d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) { |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 2138 | event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type); |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 2139 | status = readl(chanbase + D40_CHAN_REG_SDLNK); |
Jonas Aaberg | 9dbfbd35c | 2010-08-09 12:08:41 +0000 | [diff] [blame] | 2140 | } else if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) { |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 2141 | event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type); |
Rabin Vincent | 8ca8468 | 2011-01-25 11:18:07 +0100 | [diff] [blame] | 2142 | status = readl(chanbase + D40_CHAN_REG_SSLNK); |
Jonas Aaberg | 9dbfbd35c | 2010-08-09 12:08:41 +0000 | [diff] [blame] | 2143 | } else { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2144 | chan_err(d40c, "Unknown direction\n"); |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 2145 | goto _exit; |
| 2146 | } |
Jonas Aaberg | 9dbfbd35c | 2010-08-09 12:08:41 +0000 | [diff] [blame] | 2147 | |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 2148 | status = (status & D40_EVENTLINE_MASK(event)) >> |
| 2149 | D40_EVENTLINE_POS(event); |
| 2150 | |
| 2151 | if (status != D40_DMA_RUN) |
| 2152 | is_paused = true; |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 2153 | _exit: |
| 2154 | spin_unlock_irqrestore(&d40c->lock, flags); |
| 2155 | return is_paused; |
| 2156 | |
| 2157 | } |
| 2158 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2159 | static u32 stedma40_residue(struct dma_chan *chan) |
| 2160 | { |
| 2161 | struct d40_chan *d40c = |
| 2162 | container_of(chan, struct d40_chan, chan); |
| 2163 | u32 bytes_left; |
| 2164 | unsigned long flags; |
| 2165 | |
| 2166 | spin_lock_irqsave(&d40c->lock, flags); |
| 2167 | bytes_left = d40_residue(d40c); |
| 2168 | spin_unlock_irqrestore(&d40c->lock, flags); |
| 2169 | |
| 2170 | return bytes_left; |
| 2171 | } |
| 2172 | |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2173 | static int |
| 2174 | d40_prep_sg_log(struct d40_chan *chan, struct d40_desc *desc, |
| 2175 | struct scatterlist *sg_src, struct scatterlist *sg_dst, |
Rabin Vincent | 822c567 | 2011-01-25 11:18:28 +0100 | [diff] [blame] | 2176 | unsigned int sg_len, dma_addr_t src_dev_addr, |
| 2177 | dma_addr_t dst_dev_addr) |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2178 | { |
| 2179 | struct stedma40_chan_cfg *cfg = &chan->dma_cfg; |
| 2180 | struct stedma40_half_channel_info *src_info = &cfg->src_info; |
| 2181 | struct stedma40_half_channel_info *dst_info = &cfg->dst_info; |
Rabin Vincent | 5ed04b8 | 2011-01-25 11:18:26 +0100 | [diff] [blame] | 2182 | int ret; |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2183 | |
Rabin Vincent | 5ed04b8 | 2011-01-25 11:18:26 +0100 | [diff] [blame] | 2184 | ret = d40_log_sg_to_lli(sg_src, sg_len, |
| 2185 | src_dev_addr, |
| 2186 | desc->lli_log.src, |
| 2187 | chan->log_def.lcsp1, |
| 2188 | src_info->data_width, |
| 2189 | dst_info->data_width); |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2190 | |
Rabin Vincent | 5ed04b8 | 2011-01-25 11:18:26 +0100 | [diff] [blame] | 2191 | ret = d40_log_sg_to_lli(sg_dst, sg_len, |
| 2192 | dst_dev_addr, |
| 2193 | desc->lli_log.dst, |
| 2194 | chan->log_def.lcsp3, |
| 2195 | dst_info->data_width, |
| 2196 | src_info->data_width); |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2197 | |
Rabin Vincent | 5ed04b8 | 2011-01-25 11:18:26 +0100 | [diff] [blame] | 2198 | return ret < 0 ? ret : 0; |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | static int |
| 2202 | d40_prep_sg_phy(struct d40_chan *chan, struct d40_desc *desc, |
| 2203 | struct scatterlist *sg_src, struct scatterlist *sg_dst, |
Rabin Vincent | 822c567 | 2011-01-25 11:18:28 +0100 | [diff] [blame] | 2204 | unsigned int sg_len, dma_addr_t src_dev_addr, |
| 2205 | dma_addr_t dst_dev_addr) |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2206 | { |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2207 | struct stedma40_chan_cfg *cfg = &chan->dma_cfg; |
| 2208 | struct stedma40_half_channel_info *src_info = &cfg->src_info; |
| 2209 | struct stedma40_half_channel_info *dst_info = &cfg->dst_info; |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2210 | unsigned long flags = 0; |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2211 | int ret; |
| 2212 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2213 | if (desc->cyclic) |
| 2214 | flags |= LLI_CYCLIC | LLI_TERM_INT; |
| 2215 | |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2216 | ret = d40_phy_sg_to_lli(sg_src, sg_len, src_dev_addr, |
| 2217 | desc->lli_phy.src, |
| 2218 | virt_to_phys(desc->lli_phy.src), |
| 2219 | chan->src_def_cfg, |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2220 | src_info, dst_info, flags); |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2221 | |
| 2222 | ret = d40_phy_sg_to_lli(sg_dst, sg_len, dst_dev_addr, |
| 2223 | desc->lli_phy.dst, |
| 2224 | virt_to_phys(desc->lli_phy.dst), |
| 2225 | chan->dst_def_cfg, |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2226 | dst_info, src_info, flags); |
Rabin Vincent | 3e3a076 | 2011-01-25 11:18:21 +0100 | [diff] [blame] | 2227 | |
| 2228 | dma_sync_single_for_device(chan->base->dev, desc->lli_pool.dma_addr, |
| 2229 | desc->lli_pool.size, DMA_TO_DEVICE); |
| 2230 | |
| 2231 | return ret < 0 ? ret : 0; |
| 2232 | } |
| 2233 | |
Rabin Vincent | 5f81158f | 2011-01-25 11:18:18 +0100 | [diff] [blame] | 2234 | static struct d40_desc * |
| 2235 | d40_prep_desc(struct d40_chan *chan, struct scatterlist *sg, |
| 2236 | unsigned int sg_len, unsigned long dma_flags) |
| 2237 | { |
| 2238 | struct stedma40_chan_cfg *cfg = &chan->dma_cfg; |
| 2239 | struct d40_desc *desc; |
Rabin Vincent | dbd8878 | 2011-01-25 11:18:19 +0100 | [diff] [blame] | 2240 | int ret; |
Rabin Vincent | 5f81158f | 2011-01-25 11:18:18 +0100 | [diff] [blame] | 2241 | |
| 2242 | desc = d40_desc_get(chan); |
| 2243 | if (!desc) |
| 2244 | return NULL; |
| 2245 | |
| 2246 | desc->lli_len = d40_sg_2_dmalen(sg, sg_len, cfg->src_info.data_width, |
| 2247 | cfg->dst_info.data_width); |
| 2248 | if (desc->lli_len < 0) { |
| 2249 | chan_err(chan, "Unaligned size\n"); |
Rabin Vincent | dbd8878 | 2011-01-25 11:18:19 +0100 | [diff] [blame] | 2250 | goto err; |
Rabin Vincent | 5f81158f | 2011-01-25 11:18:18 +0100 | [diff] [blame] | 2251 | } |
| 2252 | |
Rabin Vincent | dbd8878 | 2011-01-25 11:18:19 +0100 | [diff] [blame] | 2253 | ret = d40_pool_lli_alloc(chan, desc, desc->lli_len); |
| 2254 | if (ret < 0) { |
| 2255 | chan_err(chan, "Could not allocate lli\n"); |
| 2256 | goto err; |
| 2257 | } |
| 2258 | |
Rabin Vincent | 5f81158f | 2011-01-25 11:18:18 +0100 | [diff] [blame] | 2259 | desc->lli_current = 0; |
| 2260 | desc->txd.flags = dma_flags; |
| 2261 | desc->txd.tx_submit = d40_tx_submit; |
| 2262 | |
| 2263 | dma_async_tx_descriptor_init(&desc->txd, &chan->chan); |
| 2264 | |
| 2265 | return desc; |
Rabin Vincent | dbd8878 | 2011-01-25 11:18:19 +0100 | [diff] [blame] | 2266 | |
| 2267 | err: |
| 2268 | d40_desc_free(chan, desc); |
| 2269 | return NULL; |
Rabin Vincent | 5f81158f | 2011-01-25 11:18:18 +0100 | [diff] [blame] | 2270 | } |
| 2271 | |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2272 | static dma_addr_t |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 2273 | d40_get_dev_addr(struct d40_chan *chan, enum dma_transfer_direction direction) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2274 | { |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2275 | struct stedma40_platform_data *plat = chan->base->plat_data; |
| 2276 | struct stedma40_chan_cfg *cfg = &chan->dma_cfg; |
Philippe Langlais | 711b9ce | 2011-05-07 17:09:43 +0200 | [diff] [blame] | 2277 | dma_addr_t addr = 0; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2278 | |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2279 | if (chan->runtime_addr) |
| 2280 | return chan->runtime_addr; |
| 2281 | |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 2282 | if (direction == DMA_DEV_TO_MEM) |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2283 | addr = plat->dev_rx[cfg->src_dev_type]; |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 2284 | else if (direction == DMA_MEM_TO_DEV) |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2285 | addr = plat->dev_tx[cfg->dst_dev_type]; |
| 2286 | |
| 2287 | return addr; |
| 2288 | } |
| 2289 | |
| 2290 | static struct dma_async_tx_descriptor * |
| 2291 | d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src, |
| 2292 | struct scatterlist *sg_dst, unsigned int sg_len, |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 2293 | enum dma_transfer_direction direction, unsigned long dma_flags) |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2294 | { |
| 2295 | struct d40_chan *chan = container_of(dchan, struct d40_chan, chan); |
Rabin Vincent | 822c567 | 2011-01-25 11:18:28 +0100 | [diff] [blame] | 2296 | dma_addr_t src_dev_addr = 0; |
| 2297 | dma_addr_t dst_dev_addr = 0; |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2298 | struct d40_desc *desc; |
| 2299 | unsigned long flags; |
| 2300 | int ret; |
| 2301 | |
| 2302 | if (!chan->phy_chan) { |
| 2303 | chan_err(chan, "Cannot prepare unallocated channel\n"); |
| 2304 | return NULL; |
Jonas Aaberg | 0d0f6b8 | 2010-06-20 21:25:31 +0000 | [diff] [blame] | 2305 | } |
| 2306 | |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2307 | spin_lock_irqsave(&chan->lock, flags); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2308 | |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2309 | desc = d40_prep_desc(chan, sg_src, sg_len, dma_flags); |
| 2310 | if (desc == NULL) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2311 | goto err; |
| 2312 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2313 | if (sg_next(&sg_src[sg_len - 1]) == sg_src) |
| 2314 | desc->cyclic = true; |
| 2315 | |
Linus Walleij | 7e426da8 | 2012-04-12 18:12:52 +0200 | [diff] [blame] | 2316 | if (direction != DMA_TRANS_NONE) { |
Rabin Vincent | 822c567 | 2011-01-25 11:18:28 +0100 | [diff] [blame] | 2317 | dma_addr_t dev_addr = d40_get_dev_addr(chan, direction); |
| 2318 | |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 2319 | if (direction == DMA_DEV_TO_MEM) |
Rabin Vincent | 822c567 | 2011-01-25 11:18:28 +0100 | [diff] [blame] | 2320 | src_dev_addr = dev_addr; |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 2321 | else if (direction == DMA_MEM_TO_DEV) |
Rabin Vincent | 822c567 | 2011-01-25 11:18:28 +0100 | [diff] [blame] | 2322 | dst_dev_addr = dev_addr; |
| 2323 | } |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2324 | |
| 2325 | if (chan_is_logical(chan)) |
| 2326 | ret = d40_prep_sg_log(chan, desc, sg_src, sg_dst, |
Rabin Vincent | 822c567 | 2011-01-25 11:18:28 +0100 | [diff] [blame] | 2327 | sg_len, src_dev_addr, dst_dev_addr); |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2328 | else |
| 2329 | ret = d40_prep_sg_phy(chan, desc, sg_src, sg_dst, |
Rabin Vincent | 822c567 | 2011-01-25 11:18:28 +0100 | [diff] [blame] | 2330 | sg_len, src_dev_addr, dst_dev_addr); |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2331 | |
| 2332 | if (ret) { |
| 2333 | chan_err(chan, "Failed to prepare %s sg job: %d\n", |
| 2334 | chan_is_logical(chan) ? "log" : "phy", ret); |
| 2335 | goto err; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2336 | } |
| 2337 | |
Per Forlin | 82babbb36 | 2011-08-29 13:33:35 +0200 | [diff] [blame] | 2338 | /* |
| 2339 | * add descriptor to the prepare queue in order to be able |
| 2340 | * to free them later in terminate_all |
| 2341 | */ |
| 2342 | list_add_tail(&desc->node, &chan->prepare_queue); |
| 2343 | |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2344 | spin_unlock_irqrestore(&chan->lock, flags); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2345 | |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2346 | return &desc->txd; |
| 2347 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2348 | err: |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2349 | if (desc) |
| 2350 | d40_desc_free(chan, desc); |
| 2351 | spin_unlock_irqrestore(&chan->lock, flags); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2352 | return NULL; |
| 2353 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2354 | |
| 2355 | bool stedma40_filter(struct dma_chan *chan, void *data) |
| 2356 | { |
| 2357 | struct stedma40_chan_cfg *info = data; |
| 2358 | struct d40_chan *d40c = |
| 2359 | container_of(chan, struct d40_chan, chan); |
| 2360 | int err; |
| 2361 | |
| 2362 | if (data) { |
| 2363 | err = d40_validate_conf(d40c, info); |
| 2364 | if (!err) |
| 2365 | d40c->dma_cfg = *info; |
| 2366 | } else |
| 2367 | err = d40_config_memcpy(d40c); |
| 2368 | |
Rabin Vincent | ce2ca12 | 2010-10-12 13:00:49 +0000 | [diff] [blame] | 2369 | if (!err) |
| 2370 | d40c->configured = true; |
| 2371 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2372 | return err == 0; |
| 2373 | } |
| 2374 | EXPORT_SYMBOL(stedma40_filter); |
| 2375 | |
Rabin Vincent | ac2c0a3 | 2011-01-25 11:18:11 +0100 | [diff] [blame] | 2376 | static void __d40_set_prio_rt(struct d40_chan *d40c, int dev_type, bool src) |
| 2377 | { |
| 2378 | bool realtime = d40c->dma_cfg.realtime; |
| 2379 | bool highprio = d40c->dma_cfg.high_priority; |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 2380 | u32 rtreg; |
Rabin Vincent | ac2c0a3 | 2011-01-25 11:18:11 +0100 | [diff] [blame] | 2381 | u32 event = D40_TYPE_TO_EVENT(dev_type); |
| 2382 | u32 group = D40_TYPE_TO_GROUP(dev_type); |
| 2383 | u32 bit = 1 << event; |
Rabin Vincent | ccc3d69 | 2012-05-17 13:47:38 +0530 | [diff] [blame] | 2384 | u32 prioreg; |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 2385 | struct d40_gen_dmac *dmac = &d40c->base->gen_dmac; |
Rabin Vincent | ccc3d69 | 2012-05-17 13:47:38 +0530 | [diff] [blame] | 2386 | |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 2387 | rtreg = realtime ? dmac->realtime_en : dmac->realtime_clear; |
Rabin Vincent | ccc3d69 | 2012-05-17 13:47:38 +0530 | [diff] [blame] | 2388 | /* |
| 2389 | * Due to a hardware bug, in some cases a logical channel triggered by |
| 2390 | * a high priority destination event line can generate extra packet |
| 2391 | * transactions. |
| 2392 | * |
| 2393 | * The workaround is to not set the high priority level for the |
| 2394 | * destination event lines that trigger logical channels. |
| 2395 | */ |
| 2396 | if (!src && chan_is_logical(d40c)) |
| 2397 | highprio = false; |
| 2398 | |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 2399 | prioreg = highprio ? dmac->high_prio_en : dmac->high_prio_clear; |
Rabin Vincent | ac2c0a3 | 2011-01-25 11:18:11 +0100 | [diff] [blame] | 2400 | |
| 2401 | /* Destination event lines are stored in the upper halfword */ |
| 2402 | if (!src) |
| 2403 | bit <<= 16; |
| 2404 | |
| 2405 | writel(bit, d40c->base->virtbase + prioreg + group * 4); |
| 2406 | writel(bit, d40c->base->virtbase + rtreg + group * 4); |
| 2407 | } |
| 2408 | |
| 2409 | static void d40_set_prio_realtime(struct d40_chan *d40c) |
| 2410 | { |
| 2411 | if (d40c->base->rev < 3) |
| 2412 | return; |
| 2413 | |
| 2414 | if ((d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) || |
| 2415 | (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_PERIPH)) |
| 2416 | __d40_set_prio_rt(d40c, d40c->dma_cfg.src_dev_type, true); |
| 2417 | |
| 2418 | if ((d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH) || |
| 2419 | (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_PERIPH)) |
| 2420 | __d40_set_prio_rt(d40c, d40c->dma_cfg.dst_dev_type, false); |
| 2421 | } |
| 2422 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2423 | /* DMA ENGINE functions */ |
| 2424 | static int d40_alloc_chan_resources(struct dma_chan *chan) |
| 2425 | { |
| 2426 | int err; |
| 2427 | unsigned long flags; |
| 2428 | struct d40_chan *d40c = |
| 2429 | container_of(chan, struct d40_chan, chan); |
Linus Walleij | ef1872e | 2010-06-20 21:24:52 +0000 | [diff] [blame] | 2430 | bool is_free_phy; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2431 | spin_lock_irqsave(&d40c->lock, flags); |
| 2432 | |
Russell King - ARM Linux | d3ee98cdc | 2012-03-06 22:35:47 +0000 | [diff] [blame] | 2433 | dma_cookie_init(chan); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2434 | |
Rabin Vincent | ce2ca12 | 2010-10-12 13:00:49 +0000 | [diff] [blame] | 2435 | /* If no dma configuration is set use default configuration (memcpy) */ |
| 2436 | if (!d40c->configured) { |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2437 | err = d40_config_memcpy(d40c); |
Jonas Aaberg | ff0b12b | 2010-06-20 21:25:15 +0000 | [diff] [blame] | 2438 | if (err) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2439 | chan_err(d40c, "Failed to configure memcpy channel\n"); |
Jonas Aaberg | ff0b12b | 2010-06-20 21:25:15 +0000 | [diff] [blame] | 2440 | goto fail; |
| 2441 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2442 | } |
| 2443 | |
Narayanan G | 5cd326f | 2011-11-30 19:20:42 +0530 | [diff] [blame] | 2444 | err = d40_allocate_channel(d40c, &is_free_phy); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2445 | if (err) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2446 | chan_err(d40c, "Failed to allocate channel\n"); |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2447 | d40c->configured = false; |
Jonas Aaberg | ff0b12b | 2010-06-20 21:25:15 +0000 | [diff] [blame] | 2448 | goto fail; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2449 | } |
| 2450 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2451 | pm_runtime_get_sync(d40c->base->dev); |
Linus Walleij | ef1872e | 2010-06-20 21:24:52 +0000 | [diff] [blame] | 2452 | /* Fill in basic CFG register values */ |
| 2453 | d40_phy_cfg(&d40c->dma_cfg, &d40c->src_def_cfg, |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 2454 | &d40c->dst_def_cfg, chan_is_logical(d40c)); |
Linus Walleij | ef1872e | 2010-06-20 21:24:52 +0000 | [diff] [blame] | 2455 | |
Rabin Vincent | ac2c0a3 | 2011-01-25 11:18:11 +0100 | [diff] [blame] | 2456 | d40_set_prio_realtime(d40c); |
| 2457 | |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 2458 | if (chan_is_logical(d40c)) { |
Linus Walleij | ef1872e | 2010-06-20 21:24:52 +0000 | [diff] [blame] | 2459 | d40_log_cfg(&d40c->dma_cfg, |
| 2460 | &d40c->log_def.lcsp1, &d40c->log_def.lcsp3); |
| 2461 | |
| 2462 | if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) |
| 2463 | d40c->lcpa = d40c->base->lcpa_base + |
Fabio Baltieri | f26e03a | 2012-12-13 17:12:37 +0100 | [diff] [blame] | 2464 | d40c->dma_cfg.src_dev_type * D40_LCPA_CHAN_SIZE; |
Linus Walleij | ef1872e | 2010-06-20 21:24:52 +0000 | [diff] [blame] | 2465 | else |
| 2466 | d40c->lcpa = d40c->base->lcpa_base + |
Fabio Baltieri | f26e03a | 2012-12-13 17:12:37 +0100 | [diff] [blame] | 2467 | d40c->dma_cfg.dst_dev_type * |
| 2468 | D40_LCPA_CHAN_SIZE + D40_LCPA_CHAN_DST_DELTA; |
Linus Walleij | ef1872e | 2010-06-20 21:24:52 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
Narayanan G | 5cd326f | 2011-11-30 19:20:42 +0530 | [diff] [blame] | 2471 | dev_dbg(chan2dev(d40c), "allocated %s channel (phy %d%s)\n", |
| 2472 | chan_is_logical(d40c) ? "logical" : "physical", |
| 2473 | d40c->phy_chan->num, |
| 2474 | d40c->dma_cfg.use_fixed_channel ? ", fixed" : ""); |
| 2475 | |
| 2476 | |
Linus Walleij | ef1872e | 2010-06-20 21:24:52 +0000 | [diff] [blame] | 2477 | /* |
| 2478 | * Only write channel configuration to the DMA if the physical |
| 2479 | * resource is free. In case of multiple logical channels |
| 2480 | * on the same physical resource, only the first write is necessary. |
| 2481 | */ |
Jonas Aaberg | b55912c | 2010-08-09 12:08:02 +0000 | [diff] [blame] | 2482 | if (is_free_phy) |
| 2483 | d40_config_write(d40c); |
Jonas Aaberg | ff0b12b | 2010-06-20 21:25:15 +0000 | [diff] [blame] | 2484 | fail: |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2485 | pm_runtime_mark_last_busy(d40c->base->dev); |
| 2486 | pm_runtime_put_autosuspend(d40c->base->dev); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2487 | spin_unlock_irqrestore(&d40c->lock, flags); |
Jonas Aaberg | ff0b12b | 2010-06-20 21:25:15 +0000 | [diff] [blame] | 2488 | return err; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | static void d40_free_chan_resources(struct dma_chan *chan) |
| 2492 | { |
| 2493 | struct d40_chan *d40c = |
| 2494 | container_of(chan, struct d40_chan, chan); |
| 2495 | int err; |
| 2496 | unsigned long flags; |
| 2497 | |
Jonas Aaberg | 0d0f6b8 | 2010-06-20 21:25:31 +0000 | [diff] [blame] | 2498 | if (d40c->phy_chan == NULL) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2499 | chan_err(d40c, "Cannot free unallocated channel\n"); |
Jonas Aaberg | 0d0f6b8 | 2010-06-20 21:25:31 +0000 | [diff] [blame] | 2500 | return; |
| 2501 | } |
| 2502 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2503 | spin_lock_irqsave(&d40c->lock, flags); |
| 2504 | |
| 2505 | err = d40_free_dma(d40c); |
| 2506 | |
| 2507 | if (err) |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2508 | chan_err(d40c, "Failed to free channel\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2509 | spin_unlock_irqrestore(&d40c->lock, flags); |
| 2510 | } |
| 2511 | |
| 2512 | static struct dma_async_tx_descriptor *d40_prep_memcpy(struct dma_chan *chan, |
| 2513 | dma_addr_t dst, |
| 2514 | dma_addr_t src, |
| 2515 | size_t size, |
Jonas Aaberg | 2a61434 | 2010-06-20 21:25:24 +0000 | [diff] [blame] | 2516 | unsigned long dma_flags) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2517 | { |
Rabin Vincent | 95944c6 | 2011-01-25 11:18:17 +0100 | [diff] [blame] | 2518 | struct scatterlist dst_sg; |
| 2519 | struct scatterlist src_sg; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2520 | |
Rabin Vincent | 95944c6 | 2011-01-25 11:18:17 +0100 | [diff] [blame] | 2521 | sg_init_table(&dst_sg, 1); |
| 2522 | sg_init_table(&src_sg, 1); |
Jonas Aaberg | 0d0f6b8 | 2010-06-20 21:25:31 +0000 | [diff] [blame] | 2523 | |
Rabin Vincent | 95944c6 | 2011-01-25 11:18:17 +0100 | [diff] [blame] | 2524 | sg_dma_address(&dst_sg) = dst; |
| 2525 | sg_dma_address(&src_sg) = src; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2526 | |
Rabin Vincent | 95944c6 | 2011-01-25 11:18:17 +0100 | [diff] [blame] | 2527 | sg_dma_len(&dst_sg) = size; |
| 2528 | sg_dma_len(&src_sg) = size; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2529 | |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2530 | return d40_prep_sg(chan, &src_sg, &dst_sg, 1, DMA_NONE, dma_flags); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2531 | } |
| 2532 | |
Ira Snyder | 0d68866 | 2010-09-30 11:46:47 +0000 | [diff] [blame] | 2533 | static struct dma_async_tx_descriptor * |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2534 | d40_prep_memcpy_sg(struct dma_chan *chan, |
| 2535 | struct scatterlist *dst_sg, unsigned int dst_nents, |
| 2536 | struct scatterlist *src_sg, unsigned int src_nents, |
| 2537 | unsigned long dma_flags) |
Ira Snyder | 0d68866 | 2010-09-30 11:46:47 +0000 | [diff] [blame] | 2538 | { |
| 2539 | if (dst_nents != src_nents) |
| 2540 | return NULL; |
| 2541 | |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2542 | return d40_prep_sg(chan, src_sg, dst_sg, src_nents, DMA_NONE, dma_flags); |
Rabin Vincent | 00ac034 | 2011-01-25 11:18:20 +0100 | [diff] [blame] | 2543 | } |
| 2544 | |
Fabio Baltieri | f26e03a | 2012-12-13 17:12:37 +0100 | [diff] [blame] | 2545 | static struct dma_async_tx_descriptor * |
| 2546 | d40_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, |
| 2547 | unsigned int sg_len, enum dma_transfer_direction direction, |
| 2548 | unsigned long dma_flags, void *context) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2549 | { |
Andy Shevchenko | a725dcc | 2013-01-10 10:53:01 +0200 | [diff] [blame] | 2550 | if (!is_slave_direction(direction)) |
Rabin Vincent | 00ac034 | 2011-01-25 11:18:20 +0100 | [diff] [blame] | 2551 | return NULL; |
| 2552 | |
Rabin Vincent | cade1d3 | 2011-01-25 11:18:23 +0100 | [diff] [blame] | 2553 | return d40_prep_sg(chan, sgl, sgl, sg_len, direction, dma_flags); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2554 | } |
| 2555 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2556 | static struct dma_async_tx_descriptor * |
| 2557 | dma40_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t dma_addr, |
| 2558 | size_t buf_len, size_t period_len, |
Peter Ujfalusi | ec8b5e4 | 2012-09-14 15:05:47 +0300 | [diff] [blame] | 2559 | enum dma_transfer_direction direction, unsigned long flags, |
| 2560 | void *context) |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2561 | { |
| 2562 | unsigned int periods = buf_len / period_len; |
| 2563 | struct dma_async_tx_descriptor *txd; |
| 2564 | struct scatterlist *sg; |
| 2565 | int i; |
| 2566 | |
Robert Marklund | 79ca7ec | 2011-06-27 11:33:24 +0200 | [diff] [blame] | 2567 | sg = kcalloc(periods + 1, sizeof(struct scatterlist), GFP_NOWAIT); |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2568 | for (i = 0; i < periods; i++) { |
| 2569 | sg_dma_address(&sg[i]) = dma_addr; |
| 2570 | sg_dma_len(&sg[i]) = period_len; |
| 2571 | dma_addr += period_len; |
| 2572 | } |
| 2573 | |
| 2574 | sg[periods].offset = 0; |
Lars-Peter Clausen | fdaf9c4 | 2012-04-25 20:50:52 +0200 | [diff] [blame] | 2575 | sg_dma_len(&sg[periods]) = 0; |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2576 | sg[periods].page_link = |
| 2577 | ((unsigned long)sg | 0x01) & ~0x02; |
| 2578 | |
| 2579 | txd = d40_prep_sg(chan, sg, sg, periods, direction, |
| 2580 | DMA_PREP_INTERRUPT); |
| 2581 | |
| 2582 | kfree(sg); |
| 2583 | |
| 2584 | return txd; |
| 2585 | } |
| 2586 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2587 | static enum dma_status d40_tx_status(struct dma_chan *chan, |
| 2588 | dma_cookie_t cookie, |
| 2589 | struct dma_tx_state *txstate) |
| 2590 | { |
| 2591 | struct d40_chan *d40c = container_of(chan, struct d40_chan, chan); |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 2592 | enum dma_status ret; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2593 | |
Jonas Aaberg | 0d0f6b8 | 2010-06-20 21:25:31 +0000 | [diff] [blame] | 2594 | if (d40c->phy_chan == NULL) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2595 | chan_err(d40c, "Cannot read status of unallocated channel\n"); |
Jonas Aaberg | 0d0f6b8 | 2010-06-20 21:25:31 +0000 | [diff] [blame] | 2596 | return -EINVAL; |
| 2597 | } |
| 2598 | |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 2599 | ret = dma_cookie_status(chan, cookie, txstate); |
| 2600 | if (ret != DMA_SUCCESS) |
| 2601 | dma_set_residue(txstate, stedma40_residue(chan)); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2602 | |
Jonas Aaberg | a5ebca4 | 2010-05-18 00:41:09 +0200 | [diff] [blame] | 2603 | if (d40_is_paused(d40c)) |
| 2604 | ret = DMA_PAUSED; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2605 | |
| 2606 | return ret; |
| 2607 | } |
| 2608 | |
| 2609 | static void d40_issue_pending(struct dma_chan *chan) |
| 2610 | { |
| 2611 | struct d40_chan *d40c = container_of(chan, struct d40_chan, chan); |
| 2612 | unsigned long flags; |
| 2613 | |
Jonas Aaberg | 0d0f6b8 | 2010-06-20 21:25:31 +0000 | [diff] [blame] | 2614 | if (d40c->phy_chan == NULL) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2615 | chan_err(d40c, "Channel is not allocated!\n"); |
Jonas Aaberg | 0d0f6b8 | 2010-06-20 21:25:31 +0000 | [diff] [blame] | 2616 | return; |
| 2617 | } |
| 2618 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2619 | spin_lock_irqsave(&d40c->lock, flags); |
| 2620 | |
Per Forlin | a8f3067 | 2011-06-26 23:29:52 +0200 | [diff] [blame] | 2621 | list_splice_tail_init(&d40c->pending_queue, &d40c->queue); |
| 2622 | |
| 2623 | /* Busy means that queued jobs are already being processed */ |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2624 | if (!d40c->busy) |
| 2625 | (void) d40_queue_start(d40c); |
| 2626 | |
| 2627 | spin_unlock_irqrestore(&d40c->lock, flags); |
| 2628 | } |
| 2629 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 2630 | static void d40_terminate_all(struct dma_chan *chan) |
| 2631 | { |
| 2632 | unsigned long flags; |
| 2633 | struct d40_chan *d40c = container_of(chan, struct d40_chan, chan); |
| 2634 | int ret; |
| 2635 | |
| 2636 | spin_lock_irqsave(&d40c->lock, flags); |
| 2637 | |
| 2638 | pm_runtime_get_sync(d40c->base->dev); |
| 2639 | ret = d40_channel_execute_command(d40c, D40_DMA_STOP); |
| 2640 | if (ret) |
| 2641 | chan_err(d40c, "Failed to stop channel\n"); |
| 2642 | |
| 2643 | d40_term_all(d40c); |
| 2644 | pm_runtime_mark_last_busy(d40c->base->dev); |
| 2645 | pm_runtime_put_autosuspend(d40c->base->dev); |
| 2646 | if (d40c->busy) { |
| 2647 | pm_runtime_mark_last_busy(d40c->base->dev); |
| 2648 | pm_runtime_put_autosuspend(d40c->base->dev); |
| 2649 | } |
| 2650 | d40c->busy = false; |
| 2651 | |
| 2652 | spin_unlock_irqrestore(&d40c->lock, flags); |
| 2653 | } |
| 2654 | |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2655 | static int |
| 2656 | dma40_config_to_halfchannel(struct d40_chan *d40c, |
| 2657 | struct stedma40_half_channel_info *info, |
| 2658 | enum dma_slave_buswidth width, |
| 2659 | u32 maxburst) |
| 2660 | { |
| 2661 | enum stedma40_periph_data_width addr_width; |
| 2662 | int psize; |
| 2663 | |
| 2664 | switch (width) { |
| 2665 | case DMA_SLAVE_BUSWIDTH_1_BYTE: |
| 2666 | addr_width = STEDMA40_BYTE_WIDTH; |
| 2667 | break; |
| 2668 | case DMA_SLAVE_BUSWIDTH_2_BYTES: |
| 2669 | addr_width = STEDMA40_HALFWORD_WIDTH; |
| 2670 | break; |
| 2671 | case DMA_SLAVE_BUSWIDTH_4_BYTES: |
| 2672 | addr_width = STEDMA40_WORD_WIDTH; |
| 2673 | break; |
| 2674 | case DMA_SLAVE_BUSWIDTH_8_BYTES: |
| 2675 | addr_width = STEDMA40_DOUBLEWORD_WIDTH; |
| 2676 | break; |
| 2677 | default: |
| 2678 | dev_err(d40c->base->dev, |
| 2679 | "illegal peripheral address width " |
| 2680 | "requested (%d)\n", |
| 2681 | width); |
| 2682 | return -EINVAL; |
| 2683 | } |
| 2684 | |
| 2685 | if (chan_is_logical(d40c)) { |
| 2686 | if (maxburst >= 16) |
| 2687 | psize = STEDMA40_PSIZE_LOG_16; |
| 2688 | else if (maxburst >= 8) |
| 2689 | psize = STEDMA40_PSIZE_LOG_8; |
| 2690 | else if (maxburst >= 4) |
| 2691 | psize = STEDMA40_PSIZE_LOG_4; |
| 2692 | else |
| 2693 | psize = STEDMA40_PSIZE_LOG_1; |
| 2694 | } else { |
| 2695 | if (maxburst >= 16) |
| 2696 | psize = STEDMA40_PSIZE_PHY_16; |
| 2697 | else if (maxburst >= 8) |
| 2698 | psize = STEDMA40_PSIZE_PHY_8; |
| 2699 | else if (maxburst >= 4) |
| 2700 | psize = STEDMA40_PSIZE_PHY_4; |
| 2701 | else |
| 2702 | psize = STEDMA40_PSIZE_PHY_1; |
| 2703 | } |
| 2704 | |
| 2705 | info->data_width = addr_width; |
| 2706 | info->psize = psize; |
| 2707 | info->flow_ctrl = STEDMA40_NO_FLOW_CTRL; |
| 2708 | |
| 2709 | return 0; |
| 2710 | } |
| 2711 | |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2712 | /* Runtime reconfiguration extension */ |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2713 | static int d40_set_runtime_config(struct dma_chan *chan, |
| 2714 | struct dma_slave_config *config) |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2715 | { |
| 2716 | struct d40_chan *d40c = container_of(chan, struct d40_chan, chan); |
| 2717 | struct stedma40_chan_cfg *cfg = &d40c->dma_cfg; |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2718 | enum dma_slave_buswidth src_addr_width, dst_addr_width; |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2719 | dma_addr_t config_addr; |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2720 | u32 src_maxburst, dst_maxburst; |
| 2721 | int ret; |
| 2722 | |
| 2723 | src_addr_width = config->src_addr_width; |
| 2724 | src_maxburst = config->src_maxburst; |
| 2725 | dst_addr_width = config->dst_addr_width; |
| 2726 | dst_maxburst = config->dst_maxburst; |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2727 | |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 2728 | if (config->direction == DMA_DEV_TO_MEM) { |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2729 | dma_addr_t dev_addr_rx = |
| 2730 | d40c->base->plat_data->dev_rx[cfg->src_dev_type]; |
| 2731 | |
| 2732 | config_addr = config->src_addr; |
| 2733 | if (dev_addr_rx) |
| 2734 | dev_dbg(d40c->base->dev, |
| 2735 | "channel has a pre-wired RX address %08x " |
| 2736 | "overriding with %08x\n", |
| 2737 | dev_addr_rx, config_addr); |
| 2738 | if (cfg->dir != STEDMA40_PERIPH_TO_MEM) |
| 2739 | dev_dbg(d40c->base->dev, |
| 2740 | "channel was not configured for peripheral " |
| 2741 | "to memory transfer (%d) overriding\n", |
| 2742 | cfg->dir); |
| 2743 | cfg->dir = STEDMA40_PERIPH_TO_MEM; |
| 2744 | |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2745 | /* Configure the memory side */ |
| 2746 | if (dst_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) |
| 2747 | dst_addr_width = src_addr_width; |
| 2748 | if (dst_maxburst == 0) |
| 2749 | dst_maxburst = src_maxburst; |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2750 | |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 2751 | } else if (config->direction == DMA_MEM_TO_DEV) { |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2752 | dma_addr_t dev_addr_tx = |
| 2753 | d40c->base->plat_data->dev_tx[cfg->dst_dev_type]; |
| 2754 | |
| 2755 | config_addr = config->dst_addr; |
| 2756 | if (dev_addr_tx) |
| 2757 | dev_dbg(d40c->base->dev, |
| 2758 | "channel has a pre-wired TX address %08x " |
| 2759 | "overriding with %08x\n", |
| 2760 | dev_addr_tx, config_addr); |
| 2761 | if (cfg->dir != STEDMA40_MEM_TO_PERIPH) |
| 2762 | dev_dbg(d40c->base->dev, |
| 2763 | "channel was not configured for memory " |
| 2764 | "to peripheral transfer (%d) overriding\n", |
| 2765 | cfg->dir); |
| 2766 | cfg->dir = STEDMA40_MEM_TO_PERIPH; |
| 2767 | |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2768 | /* Configure the memory side */ |
| 2769 | if (src_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) |
| 2770 | src_addr_width = dst_addr_width; |
| 2771 | if (src_maxburst == 0) |
| 2772 | src_maxburst = dst_maxburst; |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2773 | } else { |
| 2774 | dev_err(d40c->base->dev, |
| 2775 | "unrecognized channel direction %d\n", |
| 2776 | config->direction); |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2777 | return -EINVAL; |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2778 | } |
| 2779 | |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2780 | if (src_maxburst * src_addr_width != dst_maxburst * dst_addr_width) { |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2781 | dev_err(d40c->base->dev, |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2782 | "src/dst width/maxburst mismatch: %d*%d != %d*%d\n", |
| 2783 | src_maxburst, |
| 2784 | src_addr_width, |
| 2785 | dst_maxburst, |
| 2786 | dst_addr_width); |
| 2787 | return -EINVAL; |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2788 | } |
| 2789 | |
Per Forlin | 92bb6cd | 2011-10-13 12:11:36 +0200 | [diff] [blame] | 2790 | if (src_maxburst > 16) { |
| 2791 | src_maxburst = 16; |
| 2792 | dst_maxburst = src_maxburst * src_addr_width / dst_addr_width; |
| 2793 | } else if (dst_maxburst > 16) { |
| 2794 | dst_maxburst = 16; |
| 2795 | src_maxburst = dst_maxburst * dst_addr_width / src_addr_width; |
| 2796 | } |
| 2797 | |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2798 | ret = dma40_config_to_halfchannel(d40c, &cfg->src_info, |
| 2799 | src_addr_width, |
| 2800 | src_maxburst); |
| 2801 | if (ret) |
| 2802 | return ret; |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2803 | |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2804 | ret = dma40_config_to_halfchannel(d40c, &cfg->dst_info, |
| 2805 | dst_addr_width, |
| 2806 | dst_maxburst); |
| 2807 | if (ret) |
| 2808 | return ret; |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2809 | |
Per Forlin | a59670a | 2010-10-06 09:05:27 +0000 | [diff] [blame] | 2810 | /* Fill in register values */ |
Rabin Vincent | 724a857 | 2011-01-25 11:18:08 +0100 | [diff] [blame] | 2811 | if (chan_is_logical(d40c)) |
Per Forlin | a59670a | 2010-10-06 09:05:27 +0000 | [diff] [blame] | 2812 | d40_log_cfg(cfg, &d40c->log_def.lcsp1, &d40c->log_def.lcsp3); |
| 2813 | else |
| 2814 | d40_phy_cfg(cfg, &d40c->src_def_cfg, |
| 2815 | &d40c->dst_def_cfg, false); |
| 2816 | |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2817 | /* These settings will take precedence later */ |
| 2818 | d40c->runtime_addr = config_addr; |
| 2819 | d40c->runtime_direction = config->direction; |
| 2820 | dev_dbg(d40c->base->dev, |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2821 | "configured channel %s for %s, data width %d/%d, " |
| 2822 | "maxburst %d/%d elements, LE, no flow control\n", |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2823 | dma_chan_name(chan), |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 2824 | (config->direction == DMA_DEV_TO_MEM) ? "RX" : "TX", |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2825 | src_addr_width, dst_addr_width, |
| 2826 | src_maxburst, dst_maxburst); |
| 2827 | |
| 2828 | return 0; |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2829 | } |
| 2830 | |
Linus Walleij | 0582763 | 2010-05-17 16:30:42 -0700 | [diff] [blame] | 2831 | static int d40_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, |
| 2832 | unsigned long arg) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2833 | { |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2834 | struct d40_chan *d40c = container_of(chan, struct d40_chan, chan); |
| 2835 | |
Jonas Aaberg | 0d0f6b8 | 2010-06-20 21:25:31 +0000 | [diff] [blame] | 2836 | if (d40c->phy_chan == NULL) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2837 | chan_err(d40c, "Channel is not allocated!\n"); |
Jonas Aaberg | 0d0f6b8 | 2010-06-20 21:25:31 +0000 | [diff] [blame] | 2838 | return -EINVAL; |
| 2839 | } |
| 2840 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2841 | switch (cmd) { |
| 2842 | case DMA_TERMINATE_ALL: |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 2843 | d40_terminate_all(chan); |
| 2844 | return 0; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2845 | case DMA_PAUSE: |
Rabin Vincent | 86eb5fb | 2011-01-25 11:18:34 +0100 | [diff] [blame] | 2846 | return d40_pause(d40c); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2847 | case DMA_RESUME: |
Rabin Vincent | 86eb5fb | 2011-01-25 11:18:34 +0100 | [diff] [blame] | 2848 | return d40_resume(d40c); |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2849 | case DMA_SLAVE_CONFIG: |
Rabin Vincent | 98ca528 | 2011-06-27 11:33:38 +0200 | [diff] [blame] | 2850 | return d40_set_runtime_config(chan, |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2851 | (struct dma_slave_config *) arg); |
Linus Walleij | 95e1400 | 2010-08-04 13:37:45 +0200 | [diff] [blame] | 2852 | default: |
| 2853 | break; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | /* Other commands are unimplemented */ |
| 2857 | return -ENXIO; |
| 2858 | } |
| 2859 | |
| 2860 | /* Initialization functions */ |
| 2861 | |
| 2862 | static void __init d40_chan_init(struct d40_base *base, struct dma_device *dma, |
| 2863 | struct d40_chan *chans, int offset, |
| 2864 | int num_chans) |
| 2865 | { |
| 2866 | int i = 0; |
| 2867 | struct d40_chan *d40c; |
| 2868 | |
| 2869 | INIT_LIST_HEAD(&dma->channels); |
| 2870 | |
| 2871 | for (i = offset; i < offset + num_chans; i++) { |
| 2872 | d40c = &chans[i]; |
| 2873 | d40c->base = base; |
| 2874 | d40c->chan.device = dma; |
| 2875 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2876 | spin_lock_init(&d40c->lock); |
| 2877 | |
| 2878 | d40c->log_num = D40_PHY_CHAN; |
| 2879 | |
Fabio Baltieri | 4226dd8 | 2012-12-13 13:46:16 +0100 | [diff] [blame] | 2880 | INIT_LIST_HEAD(&d40c->done); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2881 | INIT_LIST_HEAD(&d40c->active); |
| 2882 | INIT_LIST_HEAD(&d40c->queue); |
Per Forlin | a8f3067 | 2011-06-26 23:29:52 +0200 | [diff] [blame] | 2883 | INIT_LIST_HEAD(&d40c->pending_queue); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2884 | INIT_LIST_HEAD(&d40c->client); |
Per Forlin | 82babbb36 | 2011-08-29 13:33:35 +0200 | [diff] [blame] | 2885 | INIT_LIST_HEAD(&d40c->prepare_queue); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2886 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2887 | tasklet_init(&d40c->tasklet, dma_tasklet, |
| 2888 | (unsigned long) d40c); |
| 2889 | |
| 2890 | list_add_tail(&d40c->chan.device_node, |
| 2891 | &dma->channels); |
| 2892 | } |
| 2893 | } |
| 2894 | |
Rabin Vincent | 7ad74a7 | 2011-01-25 11:18:33 +0100 | [diff] [blame] | 2895 | static void d40_ops_init(struct d40_base *base, struct dma_device *dev) |
| 2896 | { |
| 2897 | if (dma_has_cap(DMA_SLAVE, dev->cap_mask)) |
| 2898 | dev->device_prep_slave_sg = d40_prep_slave_sg; |
| 2899 | |
| 2900 | if (dma_has_cap(DMA_MEMCPY, dev->cap_mask)) { |
| 2901 | dev->device_prep_dma_memcpy = d40_prep_memcpy; |
| 2902 | |
| 2903 | /* |
| 2904 | * This controller can only access address at even |
| 2905 | * 32bit boundaries, i.e. 2^2 |
| 2906 | */ |
| 2907 | dev->copy_align = 2; |
| 2908 | } |
| 2909 | |
| 2910 | if (dma_has_cap(DMA_SG, dev->cap_mask)) |
| 2911 | dev->device_prep_dma_sg = d40_prep_memcpy_sg; |
| 2912 | |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2913 | if (dma_has_cap(DMA_CYCLIC, dev->cap_mask)) |
| 2914 | dev->device_prep_dma_cyclic = dma40_prep_dma_cyclic; |
| 2915 | |
Rabin Vincent | 7ad74a7 | 2011-01-25 11:18:33 +0100 | [diff] [blame] | 2916 | dev->device_alloc_chan_resources = d40_alloc_chan_resources; |
| 2917 | dev->device_free_chan_resources = d40_free_chan_resources; |
| 2918 | dev->device_issue_pending = d40_issue_pending; |
| 2919 | dev->device_tx_status = d40_tx_status; |
| 2920 | dev->device_control = d40_control; |
| 2921 | dev->dev = base->dev; |
| 2922 | } |
| 2923 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2924 | static int __init d40_dmaengine_init(struct d40_base *base, |
| 2925 | int num_reserved_chans) |
| 2926 | { |
| 2927 | int err ; |
| 2928 | |
| 2929 | d40_chan_init(base, &base->dma_slave, base->log_chans, |
| 2930 | 0, base->num_log_chans); |
| 2931 | |
| 2932 | dma_cap_zero(base->dma_slave.cap_mask); |
| 2933 | dma_cap_set(DMA_SLAVE, base->dma_slave.cap_mask); |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2934 | dma_cap_set(DMA_CYCLIC, base->dma_slave.cap_mask); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2935 | |
Rabin Vincent | 7ad74a7 | 2011-01-25 11:18:33 +0100 | [diff] [blame] | 2936 | d40_ops_init(base, &base->dma_slave); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2937 | |
| 2938 | err = dma_async_device_register(&base->dma_slave); |
| 2939 | |
| 2940 | if (err) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2941 | d40_err(base->dev, "Failed to register slave channels\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2942 | goto failure1; |
| 2943 | } |
| 2944 | |
| 2945 | d40_chan_init(base, &base->dma_memcpy, base->log_chans, |
Lee Jones | 664a57e | 2013-05-03 15:31:53 +0100 | [diff] [blame] | 2946 | base->num_log_chans, ARRAY_SIZE(dma40_memcpy_channels)); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2947 | |
| 2948 | dma_cap_zero(base->dma_memcpy.cap_mask); |
| 2949 | dma_cap_set(DMA_MEMCPY, base->dma_memcpy.cap_mask); |
Rabin Vincent | 7ad74a7 | 2011-01-25 11:18:33 +0100 | [diff] [blame] | 2950 | dma_cap_set(DMA_SG, base->dma_memcpy.cap_mask); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2951 | |
Rabin Vincent | 7ad74a7 | 2011-01-25 11:18:33 +0100 | [diff] [blame] | 2952 | d40_ops_init(base, &base->dma_memcpy); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2953 | |
| 2954 | err = dma_async_device_register(&base->dma_memcpy); |
| 2955 | |
| 2956 | if (err) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2957 | d40_err(base->dev, |
| 2958 | "Failed to regsiter memcpy only channels\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2959 | goto failure2; |
| 2960 | } |
| 2961 | |
| 2962 | d40_chan_init(base, &base->dma_both, base->phy_chans, |
| 2963 | 0, num_reserved_chans); |
| 2964 | |
| 2965 | dma_cap_zero(base->dma_both.cap_mask); |
| 2966 | dma_cap_set(DMA_SLAVE, base->dma_both.cap_mask); |
| 2967 | dma_cap_set(DMA_MEMCPY, base->dma_both.cap_mask); |
Rabin Vincent | 7ad74a7 | 2011-01-25 11:18:33 +0100 | [diff] [blame] | 2968 | dma_cap_set(DMA_SG, base->dma_both.cap_mask); |
Rabin Vincent | 0c842b5 | 2011-01-25 11:18:35 +0100 | [diff] [blame] | 2969 | dma_cap_set(DMA_CYCLIC, base->dma_slave.cap_mask); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2970 | |
Rabin Vincent | 7ad74a7 | 2011-01-25 11:18:33 +0100 | [diff] [blame] | 2971 | d40_ops_init(base, &base->dma_both); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2972 | err = dma_async_device_register(&base->dma_both); |
| 2973 | |
| 2974 | if (err) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 2975 | d40_err(base->dev, |
| 2976 | "Failed to register logical and physical capable channels\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 2977 | goto failure3; |
| 2978 | } |
| 2979 | return 0; |
| 2980 | failure3: |
| 2981 | dma_async_device_unregister(&base->dma_memcpy); |
| 2982 | failure2: |
| 2983 | dma_async_device_unregister(&base->dma_slave); |
| 2984 | failure1: |
| 2985 | return err; |
| 2986 | } |
| 2987 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2988 | /* Suspend resume functionality */ |
| 2989 | #ifdef CONFIG_PM |
| 2990 | static int dma40_pm_suspend(struct device *dev) |
| 2991 | { |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 2992 | struct platform_device *pdev = to_platform_device(dev); |
| 2993 | struct d40_base *base = platform_get_drvdata(pdev); |
| 2994 | int ret = 0; |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2995 | |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 2996 | if (base->lcpa_regulator) |
| 2997 | ret = regulator_disable(base->lcpa_regulator); |
| 2998 | return ret; |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | static int dma40_runtime_suspend(struct device *dev) |
| 3002 | { |
| 3003 | struct platform_device *pdev = to_platform_device(dev); |
| 3004 | struct d40_base *base = platform_get_drvdata(pdev); |
| 3005 | |
| 3006 | d40_save_restore_registers(base, true); |
| 3007 | |
| 3008 | /* Don't disable/enable clocks for v1 due to HW bugs */ |
| 3009 | if (base->rev != 1) |
| 3010 | writel_relaxed(base->gcc_pwr_off_mask, |
| 3011 | base->virtbase + D40_DREG_GCC); |
| 3012 | |
| 3013 | return 0; |
| 3014 | } |
| 3015 | |
| 3016 | static int dma40_runtime_resume(struct device *dev) |
| 3017 | { |
| 3018 | struct platform_device *pdev = to_platform_device(dev); |
| 3019 | struct d40_base *base = platform_get_drvdata(pdev); |
| 3020 | |
| 3021 | if (base->initialized) |
| 3022 | d40_save_restore_registers(base, false); |
| 3023 | |
| 3024 | writel_relaxed(D40_DREG_GCC_ENABLE_ALL, |
| 3025 | base->virtbase + D40_DREG_GCC); |
| 3026 | return 0; |
| 3027 | } |
| 3028 | |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 3029 | static int dma40_resume(struct device *dev) |
| 3030 | { |
| 3031 | struct platform_device *pdev = to_platform_device(dev); |
| 3032 | struct d40_base *base = platform_get_drvdata(pdev); |
| 3033 | int ret = 0; |
| 3034 | |
| 3035 | if (base->lcpa_regulator) |
| 3036 | ret = regulator_enable(base->lcpa_regulator); |
| 3037 | |
| 3038 | return ret; |
| 3039 | } |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3040 | |
| 3041 | static const struct dev_pm_ops dma40_pm_ops = { |
| 3042 | .suspend = dma40_pm_suspend, |
| 3043 | .runtime_suspend = dma40_runtime_suspend, |
| 3044 | .runtime_resume = dma40_runtime_resume, |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 3045 | .resume = dma40_resume, |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3046 | }; |
| 3047 | #define DMA40_PM_OPS (&dma40_pm_ops) |
| 3048 | #else |
| 3049 | #define DMA40_PM_OPS NULL |
| 3050 | #endif |
| 3051 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3052 | /* Initialization functions. */ |
| 3053 | |
| 3054 | static int __init d40_phy_res_init(struct d40_base *base) |
| 3055 | { |
| 3056 | int i; |
| 3057 | int num_phy_chans_avail = 0; |
| 3058 | u32 val[2]; |
| 3059 | int odd_even_bit = -2; |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3060 | int gcc = D40_DREG_GCC_ENA; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3061 | |
| 3062 | val[0] = readl(base->virtbase + D40_DREG_PRSME); |
| 3063 | val[1] = readl(base->virtbase + D40_DREG_PRSMO); |
| 3064 | |
| 3065 | for (i = 0; i < base->num_phy_chans; i++) { |
| 3066 | base->phy_res[i].num = i; |
| 3067 | odd_even_bit += 2 * ((i % 2) == 0); |
| 3068 | if (((val[i % 2] >> odd_even_bit) & 3) == 1) { |
| 3069 | /* Mark security only channels as occupied */ |
| 3070 | base->phy_res[i].allocated_src = D40_ALLOC_PHY; |
| 3071 | base->phy_res[i].allocated_dst = D40_ALLOC_PHY; |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3072 | base->phy_res[i].reserved = true; |
| 3073 | gcc |= D40_DREG_GCC_EVTGRP_ENA(D40_PHYS_TO_GROUP(i), |
| 3074 | D40_DREG_GCC_SRC); |
| 3075 | gcc |= D40_DREG_GCC_EVTGRP_ENA(D40_PHYS_TO_GROUP(i), |
| 3076 | D40_DREG_GCC_DST); |
| 3077 | |
| 3078 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3079 | } else { |
| 3080 | base->phy_res[i].allocated_src = D40_ALLOC_FREE; |
| 3081 | base->phy_res[i].allocated_dst = D40_ALLOC_FREE; |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3082 | base->phy_res[i].reserved = false; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3083 | num_phy_chans_avail++; |
| 3084 | } |
| 3085 | spin_lock_init(&base->phy_res[i].lock); |
| 3086 | } |
Jonas Aaberg | 6b7acd8 | 2010-06-20 21:26:59 +0000 | [diff] [blame] | 3087 | |
| 3088 | /* Mark disabled channels as occupied */ |
| 3089 | for (i = 0; base->plat_data->disabled_channels[i] != -1; i++) { |
Rabin Vincent | f57b407 | 2010-10-06 08:20:35 +0000 | [diff] [blame] | 3090 | int chan = base->plat_data->disabled_channels[i]; |
| 3091 | |
| 3092 | base->phy_res[chan].allocated_src = D40_ALLOC_PHY; |
| 3093 | base->phy_res[chan].allocated_dst = D40_ALLOC_PHY; |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3094 | base->phy_res[chan].reserved = true; |
| 3095 | gcc |= D40_DREG_GCC_EVTGRP_ENA(D40_PHYS_TO_GROUP(chan), |
| 3096 | D40_DREG_GCC_SRC); |
| 3097 | gcc |= D40_DREG_GCC_EVTGRP_ENA(D40_PHYS_TO_GROUP(chan), |
| 3098 | D40_DREG_GCC_DST); |
Rabin Vincent | f57b407 | 2010-10-06 08:20:35 +0000 | [diff] [blame] | 3099 | num_phy_chans_avail--; |
Jonas Aaberg | 6b7acd8 | 2010-06-20 21:26:59 +0000 | [diff] [blame] | 3100 | } |
| 3101 | |
Fabio Baltieri | 7407048 | 2012-12-18 12:25:14 +0100 | [diff] [blame] | 3102 | /* Mark soft_lli channels */ |
| 3103 | for (i = 0; i < base->plat_data->num_of_soft_lli_chans; i++) { |
| 3104 | int chan = base->plat_data->soft_lli_chans[i]; |
| 3105 | |
| 3106 | base->phy_res[chan].use_soft_lli = true; |
| 3107 | } |
| 3108 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3109 | dev_info(base->dev, "%d of %d physical DMA channels available\n", |
| 3110 | num_phy_chans_avail, base->num_phy_chans); |
| 3111 | |
| 3112 | /* Verify settings extended vs standard */ |
| 3113 | val[0] = readl(base->virtbase + D40_DREG_PRTYP); |
| 3114 | |
| 3115 | for (i = 0; i < base->num_phy_chans; i++) { |
| 3116 | |
| 3117 | if (base->phy_res[i].allocated_src == D40_ALLOC_FREE && |
| 3118 | (val[0] & 0x3) != 1) |
| 3119 | dev_info(base->dev, |
| 3120 | "[%s] INFO: channel %d is misconfigured (%d)\n", |
| 3121 | __func__, i, val[0] & 0x3); |
| 3122 | |
| 3123 | val[0] = val[0] >> 2; |
| 3124 | } |
| 3125 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3126 | /* |
| 3127 | * To keep things simple, Enable all clocks initially. |
| 3128 | * The clocks will get managed later post channel allocation. |
| 3129 | * The clocks for the event lines on which reserved channels exists |
| 3130 | * are not managed here. |
| 3131 | */ |
| 3132 | writel(D40_DREG_GCC_ENABLE_ALL, base->virtbase + D40_DREG_GCC); |
| 3133 | base->gcc_pwr_off_mask = gcc; |
| 3134 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3135 | return num_phy_chans_avail; |
| 3136 | } |
| 3137 | |
| 3138 | static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) |
| 3139 | { |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3140 | struct stedma40_platform_data *plat_data; |
| 3141 | struct clk *clk = NULL; |
| 3142 | void __iomem *virtbase = NULL; |
| 3143 | struct resource *res = NULL; |
| 3144 | struct d40_base *base = NULL; |
| 3145 | int num_log_chans = 0; |
| 3146 | int num_phy_chans; |
Ulf Hansson | b707c658 | 2012-08-23 13:41:58 +0200 | [diff] [blame] | 3147 | int clk_ret = -EINVAL; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3148 | int i; |
Linus Walleij | f4b8976 | 2011-06-27 11:33:46 +0200 | [diff] [blame] | 3149 | u32 pid; |
| 3150 | u32 cid; |
| 3151 | u8 rev; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3152 | |
| 3153 | clk = clk_get(&pdev->dev, NULL); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3154 | if (IS_ERR(clk)) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 3155 | d40_err(&pdev->dev, "No matching clock found\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3156 | goto failure; |
| 3157 | } |
| 3158 | |
Ulf Hansson | b707c658 | 2012-08-23 13:41:58 +0200 | [diff] [blame] | 3159 | clk_ret = clk_prepare_enable(clk); |
| 3160 | if (clk_ret) { |
| 3161 | d40_err(&pdev->dev, "Failed to prepare/enable clock\n"); |
| 3162 | goto failure; |
| 3163 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3164 | |
| 3165 | /* Get IO for DMAC base address */ |
| 3166 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "base"); |
| 3167 | if (!res) |
| 3168 | goto failure; |
| 3169 | |
| 3170 | if (request_mem_region(res->start, resource_size(res), |
| 3171 | D40_NAME " I/O base") == NULL) |
| 3172 | goto failure; |
| 3173 | |
| 3174 | virtbase = ioremap(res->start, resource_size(res)); |
| 3175 | if (!virtbase) |
| 3176 | goto failure; |
| 3177 | |
Linus Walleij | f4b8976 | 2011-06-27 11:33:46 +0200 | [diff] [blame] | 3178 | /* This is just a regular AMBA PrimeCell ID actually */ |
| 3179 | for (pid = 0, i = 0; i < 4; i++) |
| 3180 | pid |= (readl(virtbase + resource_size(res) - 0x20 + 4 * i) |
| 3181 | & 255) << (i * 8); |
| 3182 | for (cid = 0, i = 0; i < 4; i++) |
| 3183 | cid |= (readl(virtbase + resource_size(res) - 0x10 + 4 * i) |
| 3184 | & 255) << (i * 8); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3185 | |
Linus Walleij | f4b8976 | 2011-06-27 11:33:46 +0200 | [diff] [blame] | 3186 | if (cid != AMBA_CID) { |
| 3187 | d40_err(&pdev->dev, "Unknown hardware! No PrimeCell ID\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3188 | goto failure; |
| 3189 | } |
Linus Walleij | f4b8976 | 2011-06-27 11:33:46 +0200 | [diff] [blame] | 3190 | if (AMBA_MANF_BITS(pid) != AMBA_VENDOR_ST) { |
| 3191 | d40_err(&pdev->dev, "Unknown designer! Got %x wanted %x\n", |
| 3192 | AMBA_MANF_BITS(pid), |
| 3193 | AMBA_VENDOR_ST); |
| 3194 | goto failure; |
| 3195 | } |
| 3196 | /* |
| 3197 | * HW revision: |
| 3198 | * DB8500ed has revision 0 |
| 3199 | * ? has revision 1 |
| 3200 | * DB8500v1 has revision 2 |
| 3201 | * DB8500v2 has revision 3 |
Gerald Baeza | 47db92f | 2012-09-21 21:21:37 +0200 | [diff] [blame] | 3202 | * AP9540v1 has revision 4 |
| 3203 | * DB8540v1 has revision 4 |
Linus Walleij | f4b8976 | 2011-06-27 11:33:46 +0200 | [diff] [blame] | 3204 | */ |
| 3205 | rev = AMBA_REV_BITS(pid); |
Jonas Aaberg | 3ae0267 | 2010-08-09 12:08:18 +0000 | [diff] [blame] | 3206 | |
Gerald Baeza | 47db92f | 2012-09-21 21:21:37 +0200 | [diff] [blame] | 3207 | plat_data = pdev->dev.platform_data; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3208 | |
Gerald Baeza | 47db92f | 2012-09-21 21:21:37 +0200 | [diff] [blame] | 3209 | /* The number of physical channels on this HW */ |
| 3210 | if (plat_data->num_of_phy_chans) |
| 3211 | num_phy_chans = plat_data->num_of_phy_chans; |
| 3212 | else |
| 3213 | num_phy_chans = 4 * (readl(virtbase + D40_DREG_ICFG) & 0x7) + 4; |
| 3214 | |
| 3215 | dev_info(&pdev->dev, "hardware revision: %d @ 0x%x with %d physical channels\n", |
| 3216 | rev, res->start, num_phy_chans); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3217 | |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 3218 | if (rev < 2) { |
| 3219 | d40_err(&pdev->dev, "hardware revision: %d is not supported", |
| 3220 | rev); |
| 3221 | goto failure; |
| 3222 | } |
| 3223 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3224 | /* Count the number of logical channels in use */ |
| 3225 | for (i = 0; i < plat_data->dev_len; i++) |
| 3226 | if (plat_data->dev_rx[i] != 0) |
| 3227 | num_log_chans++; |
| 3228 | |
| 3229 | for (i = 0; i < plat_data->dev_len; i++) |
| 3230 | if (plat_data->dev_tx[i] != 0) |
| 3231 | num_log_chans++; |
| 3232 | |
| 3233 | base = kzalloc(ALIGN(sizeof(struct d40_base), 4) + |
Lee Jones | 664a57e | 2013-05-03 15:31:53 +0100 | [diff] [blame] | 3234 | (num_phy_chans + num_log_chans + ARRAY_SIZE(dma40_memcpy_channels)) * |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3235 | sizeof(struct d40_chan), GFP_KERNEL); |
| 3236 | |
| 3237 | if (base == NULL) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 3238 | d40_err(&pdev->dev, "Out of memory\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3239 | goto failure; |
| 3240 | } |
| 3241 | |
Jonas Aaberg | 3ae0267 | 2010-08-09 12:08:18 +0000 | [diff] [blame] | 3242 | base->rev = rev; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3243 | base->clk = clk; |
| 3244 | base->num_phy_chans = num_phy_chans; |
| 3245 | base->num_log_chans = num_log_chans; |
| 3246 | base->phy_start = res->start; |
| 3247 | base->phy_size = resource_size(res); |
| 3248 | base->virtbase = virtbase; |
| 3249 | base->plat_data = plat_data; |
| 3250 | base->dev = &pdev->dev; |
| 3251 | base->phy_chans = ((void *)base) + ALIGN(sizeof(struct d40_base), 4); |
| 3252 | base->log_chans = &base->phy_chans[num_phy_chans]; |
| 3253 | |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 3254 | if (base->plat_data->num_of_phy_chans == 14) { |
| 3255 | base->gen_dmac.backup = d40_backup_regs_v4b; |
| 3256 | base->gen_dmac.backup_size = BACKUP_REGS_SZ_V4B; |
| 3257 | base->gen_dmac.interrupt_en = D40_DREG_CPCMIS; |
| 3258 | base->gen_dmac.interrupt_clear = D40_DREG_CPCICR; |
| 3259 | base->gen_dmac.realtime_en = D40_DREG_CRSEG1; |
| 3260 | base->gen_dmac.realtime_clear = D40_DREG_CRCEG1; |
| 3261 | base->gen_dmac.high_prio_en = D40_DREG_CPSEG1; |
| 3262 | base->gen_dmac.high_prio_clear = D40_DREG_CPCEG1; |
| 3263 | base->gen_dmac.il = il_v4b; |
| 3264 | base->gen_dmac.il_size = ARRAY_SIZE(il_v4b); |
| 3265 | base->gen_dmac.init_reg = dma_init_reg_v4b; |
| 3266 | base->gen_dmac.init_reg_size = ARRAY_SIZE(dma_init_reg_v4b); |
| 3267 | } else { |
| 3268 | if (base->rev >= 3) { |
| 3269 | base->gen_dmac.backup = d40_backup_regs_v4a; |
| 3270 | base->gen_dmac.backup_size = BACKUP_REGS_SZ_V4A; |
| 3271 | } |
| 3272 | base->gen_dmac.interrupt_en = D40_DREG_PCMIS; |
| 3273 | base->gen_dmac.interrupt_clear = D40_DREG_PCICR; |
| 3274 | base->gen_dmac.realtime_en = D40_DREG_RSEG1; |
| 3275 | base->gen_dmac.realtime_clear = D40_DREG_RCEG1; |
| 3276 | base->gen_dmac.high_prio_en = D40_DREG_PSEG1; |
| 3277 | base->gen_dmac.high_prio_clear = D40_DREG_PCEG1; |
| 3278 | base->gen_dmac.il = il_v4a; |
| 3279 | base->gen_dmac.il_size = ARRAY_SIZE(il_v4a); |
| 3280 | base->gen_dmac.init_reg = dma_init_reg_v4a; |
| 3281 | base->gen_dmac.init_reg_size = ARRAY_SIZE(dma_init_reg_v4a); |
| 3282 | } |
| 3283 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3284 | base->phy_res = kzalloc(num_phy_chans * sizeof(struct d40_phy_res), |
| 3285 | GFP_KERNEL); |
| 3286 | if (!base->phy_res) |
| 3287 | goto failure; |
| 3288 | |
| 3289 | base->lookup_phy_chans = kzalloc(num_phy_chans * |
| 3290 | sizeof(struct d40_chan *), |
| 3291 | GFP_KERNEL); |
| 3292 | if (!base->lookup_phy_chans) |
| 3293 | goto failure; |
| 3294 | |
Lee Jones | 664a57e | 2013-05-03 15:31:53 +0100 | [diff] [blame] | 3295 | if (num_log_chans + ARRAY_SIZE(dma40_memcpy_channels)) { |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3296 | /* |
| 3297 | * The max number of logical channels are event lines for all |
| 3298 | * src devices and dst devices |
| 3299 | */ |
| 3300 | base->lookup_log_chans = kzalloc(plat_data->dev_len * 2 * |
| 3301 | sizeof(struct d40_chan *), |
| 3302 | GFP_KERNEL); |
| 3303 | if (!base->lookup_log_chans) |
| 3304 | goto failure; |
| 3305 | } |
Jonas Aaberg | 698e473 | 2010-08-09 12:08:56 +0000 | [diff] [blame] | 3306 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3307 | base->reg_val_backup_chan = kmalloc(base->num_phy_chans * |
| 3308 | sizeof(d40_backup_regs_chan), |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3309 | GFP_KERNEL); |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3310 | if (!base->reg_val_backup_chan) |
| 3311 | goto failure; |
| 3312 | |
| 3313 | base->lcla_pool.alloc_map = |
| 3314 | kzalloc(num_phy_chans * sizeof(struct d40_desc *) |
| 3315 | * D40_LCLA_LINK_PER_EVENT_GRP, GFP_KERNEL); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3316 | if (!base->lcla_pool.alloc_map) |
| 3317 | goto failure; |
| 3318 | |
Jonas Aaberg | c675b1b | 2010-06-20 21:25:08 +0000 | [diff] [blame] | 3319 | base->desc_slab = kmem_cache_create(D40_NAME, sizeof(struct d40_desc), |
| 3320 | 0, SLAB_HWCACHE_ALIGN, |
| 3321 | NULL); |
| 3322 | if (base->desc_slab == NULL) |
| 3323 | goto failure; |
| 3324 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3325 | return base; |
| 3326 | |
| 3327 | failure: |
Ulf Hansson | b707c658 | 2012-08-23 13:41:58 +0200 | [diff] [blame] | 3328 | if (!clk_ret) |
| 3329 | clk_disable_unprepare(clk); |
| 3330 | if (!IS_ERR(clk)) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3331 | clk_put(clk); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3332 | if (virtbase) |
| 3333 | iounmap(virtbase); |
| 3334 | if (res) |
| 3335 | release_mem_region(res->start, |
| 3336 | resource_size(res)); |
| 3337 | if (virtbase) |
| 3338 | iounmap(virtbase); |
| 3339 | |
| 3340 | if (base) { |
| 3341 | kfree(base->lcla_pool.alloc_map); |
Narayanan G | 1bdae6f | 2012-02-09 12:41:37 +0530 | [diff] [blame] | 3342 | kfree(base->reg_val_backup_chan); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3343 | kfree(base->lookup_log_chans); |
| 3344 | kfree(base->lookup_phy_chans); |
| 3345 | kfree(base->phy_res); |
| 3346 | kfree(base); |
| 3347 | } |
| 3348 | |
| 3349 | return NULL; |
| 3350 | } |
| 3351 | |
| 3352 | static void __init d40_hw_init(struct d40_base *base) |
| 3353 | { |
| 3354 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3355 | int i; |
| 3356 | u32 prmseo[2] = {0, 0}; |
| 3357 | u32 activeo[2] = {0xFFFFFFFF, 0xFFFFFFFF}; |
| 3358 | u32 pcmis = 0; |
| 3359 | u32 pcicr = 0; |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 3360 | struct d40_reg_val *dma_init_reg = base->gen_dmac.init_reg; |
| 3361 | u32 reg_size = base->gen_dmac.init_reg_size; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3362 | |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 3363 | for (i = 0; i < reg_size; i++) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3364 | writel(dma_init_reg[i].val, |
| 3365 | base->virtbase + dma_init_reg[i].reg); |
| 3366 | |
| 3367 | /* Configure all our dma channels to default settings */ |
| 3368 | for (i = 0; i < base->num_phy_chans; i++) { |
| 3369 | |
| 3370 | activeo[i % 2] = activeo[i % 2] << 2; |
| 3371 | |
| 3372 | if (base->phy_res[base->num_phy_chans - i - 1].allocated_src |
| 3373 | == D40_ALLOC_PHY) { |
| 3374 | activeo[i % 2] |= 3; |
| 3375 | continue; |
| 3376 | } |
| 3377 | |
| 3378 | /* Enable interrupt # */ |
| 3379 | pcmis = (pcmis << 1) | 1; |
| 3380 | |
| 3381 | /* Clear interrupt # */ |
| 3382 | pcicr = (pcicr << 1) | 1; |
| 3383 | |
| 3384 | /* Set channel to physical mode */ |
| 3385 | prmseo[i % 2] = prmseo[i % 2] << 2; |
| 3386 | prmseo[i % 2] |= 1; |
| 3387 | |
| 3388 | } |
| 3389 | |
| 3390 | writel(prmseo[1], base->virtbase + D40_DREG_PRMSE); |
| 3391 | writel(prmseo[0], base->virtbase + D40_DREG_PRMSO); |
| 3392 | writel(activeo[1], base->virtbase + D40_DREG_ACTIVE); |
| 3393 | writel(activeo[0], base->virtbase + D40_DREG_ACTIVO); |
| 3394 | |
| 3395 | /* Write which interrupt to enable */ |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 3396 | writel(pcmis, base->virtbase + base->gen_dmac.interrupt_en); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3397 | |
| 3398 | /* Write which interrupt to clear */ |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 3399 | writel(pcicr, base->virtbase + base->gen_dmac.interrupt_clear); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3400 | |
Tong Liu | 3cb645d | 2012-09-26 10:07:30 +0000 | [diff] [blame] | 3401 | /* These are __initdata and cannot be accessed after init */ |
| 3402 | base->gen_dmac.init_reg = NULL; |
| 3403 | base->gen_dmac.init_reg_size = 0; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3404 | } |
| 3405 | |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 3406 | static int __init d40_lcla_allocate(struct d40_base *base) |
| 3407 | { |
Rabin Vincent | 026cbc4 | 2011-01-25 11:18:14 +0100 | [diff] [blame] | 3408 | struct d40_lcla_pool *pool = &base->lcla_pool; |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 3409 | unsigned long *page_list; |
| 3410 | int i, j; |
| 3411 | int ret = 0; |
| 3412 | |
| 3413 | /* |
| 3414 | * This is somewhat ugly. We need 8192 bytes that are 18 bit aligned, |
| 3415 | * To full fill this hardware requirement without wasting 256 kb |
| 3416 | * we allocate pages until we get an aligned one. |
| 3417 | */ |
| 3418 | page_list = kmalloc(sizeof(unsigned long) * MAX_LCLA_ALLOC_ATTEMPTS, |
| 3419 | GFP_KERNEL); |
| 3420 | |
| 3421 | if (!page_list) { |
| 3422 | ret = -ENOMEM; |
| 3423 | goto failure; |
| 3424 | } |
| 3425 | |
| 3426 | /* Calculating how many pages that are required */ |
| 3427 | base->lcla_pool.pages = SZ_1K * base->num_phy_chans / PAGE_SIZE; |
| 3428 | |
| 3429 | for (i = 0; i < MAX_LCLA_ALLOC_ATTEMPTS; i++) { |
| 3430 | page_list[i] = __get_free_pages(GFP_KERNEL, |
| 3431 | base->lcla_pool.pages); |
| 3432 | if (!page_list[i]) { |
| 3433 | |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 3434 | d40_err(base->dev, "Failed to allocate %d pages.\n", |
| 3435 | base->lcla_pool.pages); |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 3436 | |
| 3437 | for (j = 0; j < i; j++) |
| 3438 | free_pages(page_list[j], base->lcla_pool.pages); |
| 3439 | goto failure; |
| 3440 | } |
| 3441 | |
| 3442 | if ((virt_to_phys((void *)page_list[i]) & |
| 3443 | (LCLA_ALIGNMENT - 1)) == 0) |
| 3444 | break; |
| 3445 | } |
| 3446 | |
| 3447 | for (j = 0; j < i; j++) |
| 3448 | free_pages(page_list[j], base->lcla_pool.pages); |
| 3449 | |
| 3450 | if (i < MAX_LCLA_ALLOC_ATTEMPTS) { |
| 3451 | base->lcla_pool.base = (void *)page_list[i]; |
| 3452 | } else { |
Jonas Aaberg | 767a967 | 2010-08-09 12:08:34 +0000 | [diff] [blame] | 3453 | /* |
| 3454 | * After many attempts and no succees with finding the correct |
| 3455 | * alignment, try with allocating a big buffer. |
| 3456 | */ |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 3457 | dev_warn(base->dev, |
| 3458 | "[%s] Failed to get %d pages @ 18 bit align.\n", |
| 3459 | __func__, base->lcla_pool.pages); |
| 3460 | base->lcla_pool.base_unaligned = kmalloc(SZ_1K * |
| 3461 | base->num_phy_chans + |
| 3462 | LCLA_ALIGNMENT, |
| 3463 | GFP_KERNEL); |
| 3464 | if (!base->lcla_pool.base_unaligned) { |
| 3465 | ret = -ENOMEM; |
| 3466 | goto failure; |
| 3467 | } |
| 3468 | |
| 3469 | base->lcla_pool.base = PTR_ALIGN(base->lcla_pool.base_unaligned, |
| 3470 | LCLA_ALIGNMENT); |
| 3471 | } |
| 3472 | |
Rabin Vincent | 026cbc4 | 2011-01-25 11:18:14 +0100 | [diff] [blame] | 3473 | pool->dma_addr = dma_map_single(base->dev, pool->base, |
| 3474 | SZ_1K * base->num_phy_chans, |
| 3475 | DMA_TO_DEVICE); |
| 3476 | if (dma_mapping_error(base->dev, pool->dma_addr)) { |
| 3477 | pool->dma_addr = 0; |
| 3478 | ret = -ENOMEM; |
| 3479 | goto failure; |
| 3480 | } |
| 3481 | |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 3482 | writel(virt_to_phys(base->lcla_pool.base), |
| 3483 | base->virtbase + D40_DREG_LCLA); |
| 3484 | failure: |
| 3485 | kfree(page_list); |
| 3486 | return ret; |
| 3487 | } |
| 3488 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3489 | static int __init d40_probe(struct platform_device *pdev) |
| 3490 | { |
| 3491 | int err; |
| 3492 | int ret = -ENOENT; |
| 3493 | struct d40_base *base; |
| 3494 | struct resource *res = NULL; |
| 3495 | int num_reserved_chans; |
| 3496 | u32 val; |
| 3497 | |
| 3498 | base = d40_hw_detect_init(pdev); |
| 3499 | |
| 3500 | if (!base) |
| 3501 | goto failure; |
| 3502 | |
| 3503 | num_reserved_chans = d40_phy_res_init(base); |
| 3504 | |
| 3505 | platform_set_drvdata(pdev, base); |
| 3506 | |
| 3507 | spin_lock_init(&base->interrupt_lock); |
| 3508 | spin_lock_init(&base->execmd_lock); |
| 3509 | |
| 3510 | /* Get IO for logical channel parameter address */ |
| 3511 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcpa"); |
| 3512 | if (!res) { |
| 3513 | ret = -ENOENT; |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 3514 | d40_err(&pdev->dev, "No \"lcpa\" memory resource\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3515 | goto failure; |
| 3516 | } |
| 3517 | base->lcpa_size = resource_size(res); |
| 3518 | base->phy_lcpa = res->start; |
| 3519 | |
| 3520 | if (request_mem_region(res->start, resource_size(res), |
| 3521 | D40_NAME " I/O lcpa") == NULL) { |
| 3522 | ret = -EBUSY; |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 3523 | d40_err(&pdev->dev, |
| 3524 | "Failed to request LCPA region 0x%x-0x%x\n", |
| 3525 | res->start, res->end); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3526 | goto failure; |
| 3527 | } |
| 3528 | |
| 3529 | /* We make use of ESRAM memory for this. */ |
| 3530 | val = readl(base->virtbase + D40_DREG_LCPA); |
| 3531 | if (res->start != val && val != 0) { |
| 3532 | dev_warn(&pdev->dev, |
| 3533 | "[%s] Mismatch LCPA dma 0x%x, def 0x%x\n", |
| 3534 | __func__, val, res->start); |
| 3535 | } else |
| 3536 | writel(res->start, base->virtbase + D40_DREG_LCPA); |
| 3537 | |
| 3538 | base->lcpa_base = ioremap(res->start, resource_size(res)); |
| 3539 | if (!base->lcpa_base) { |
| 3540 | ret = -ENOMEM; |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 3541 | d40_err(&pdev->dev, "Failed to ioremap LCPA region\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3542 | goto failure; |
| 3543 | } |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 3544 | /* If lcla has to be located in ESRAM we don't need to allocate */ |
| 3545 | if (base->plat_data->use_esram_lcla) { |
| 3546 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 3547 | "lcla_esram"); |
| 3548 | if (!res) { |
| 3549 | ret = -ENOENT; |
| 3550 | d40_err(&pdev->dev, |
| 3551 | "No \"lcla_esram\" memory resource\n"); |
| 3552 | goto failure; |
| 3553 | } |
| 3554 | base->lcla_pool.base = ioremap(res->start, |
| 3555 | resource_size(res)); |
| 3556 | if (!base->lcla_pool.base) { |
| 3557 | ret = -ENOMEM; |
| 3558 | d40_err(&pdev->dev, "Failed to ioremap LCLA region\n"); |
| 3559 | goto failure; |
| 3560 | } |
| 3561 | writel(res->start, base->virtbase + D40_DREG_LCLA); |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 3562 | |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 3563 | } else { |
| 3564 | ret = d40_lcla_allocate(base); |
| 3565 | if (ret) { |
| 3566 | d40_err(&pdev->dev, "Failed to allocate LCLA area\n"); |
| 3567 | goto failure; |
| 3568 | } |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3569 | } |
| 3570 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3571 | spin_lock_init(&base->lcla_pool.lock); |
| 3572 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3573 | base->irq = platform_get_irq(pdev, 0); |
| 3574 | |
| 3575 | ret = request_irq(base->irq, d40_handle_interrupt, 0, D40_NAME, base); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3576 | if (ret) { |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 3577 | d40_err(&pdev->dev, "No IRQ defined\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3578 | goto failure; |
| 3579 | } |
| 3580 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3581 | pm_runtime_irq_safe(base->dev); |
| 3582 | pm_runtime_set_autosuspend_delay(base->dev, DMA40_AUTOSUSPEND_DELAY); |
| 3583 | pm_runtime_use_autosuspend(base->dev); |
| 3584 | pm_runtime_enable(base->dev); |
| 3585 | pm_runtime_resume(base->dev); |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 3586 | |
| 3587 | if (base->plat_data->use_esram_lcla) { |
| 3588 | |
| 3589 | base->lcpa_regulator = regulator_get(base->dev, "lcla_esram"); |
| 3590 | if (IS_ERR(base->lcpa_regulator)) { |
| 3591 | d40_err(&pdev->dev, "Failed to get lcpa_regulator\n"); |
| 3592 | base->lcpa_regulator = NULL; |
| 3593 | goto failure; |
| 3594 | } |
| 3595 | |
| 3596 | ret = regulator_enable(base->lcpa_regulator); |
| 3597 | if (ret) { |
| 3598 | d40_err(&pdev->dev, |
| 3599 | "Failed to enable lcpa_regulator\n"); |
| 3600 | regulator_put(base->lcpa_regulator); |
| 3601 | base->lcpa_regulator = NULL; |
| 3602 | goto failure; |
| 3603 | } |
| 3604 | } |
| 3605 | |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3606 | base->initialized = true; |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3607 | err = d40_dmaengine_init(base, num_reserved_chans); |
| 3608 | if (err) |
| 3609 | goto failure; |
| 3610 | |
Per Forlin | b96710e | 2011-10-18 18:39:47 +0200 | [diff] [blame] | 3611 | base->dev->dma_parms = &base->dma_parms; |
| 3612 | err = dma_set_max_seg_size(base->dev, STEDMA40_MAX_SEG_SIZE); |
| 3613 | if (err) { |
| 3614 | d40_err(&pdev->dev, "Failed to set dma max seg size\n"); |
| 3615 | goto failure; |
| 3616 | } |
| 3617 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3618 | d40_hw_init(base); |
| 3619 | |
| 3620 | dev_info(base->dev, "initialized\n"); |
| 3621 | return 0; |
| 3622 | |
| 3623 | failure: |
| 3624 | if (base) { |
Jonas Aaberg | c675b1b | 2010-06-20 21:25:08 +0000 | [diff] [blame] | 3625 | if (base->desc_slab) |
| 3626 | kmem_cache_destroy(base->desc_slab); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3627 | if (base->virtbase) |
| 3628 | iounmap(base->virtbase); |
Rabin Vincent | 026cbc4 | 2011-01-25 11:18:14 +0100 | [diff] [blame] | 3629 | |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 3630 | if (base->lcla_pool.base && base->plat_data->use_esram_lcla) { |
| 3631 | iounmap(base->lcla_pool.base); |
| 3632 | base->lcla_pool.base = NULL; |
| 3633 | } |
| 3634 | |
Rabin Vincent | 026cbc4 | 2011-01-25 11:18:14 +0100 | [diff] [blame] | 3635 | if (base->lcla_pool.dma_addr) |
| 3636 | dma_unmap_single(base->dev, base->lcla_pool.dma_addr, |
| 3637 | SZ_1K * base->num_phy_chans, |
| 3638 | DMA_TO_DEVICE); |
| 3639 | |
Linus Walleij | 508849a | 2010-06-20 21:26:07 +0000 | [diff] [blame] | 3640 | if (!base->lcla_pool.base_unaligned && base->lcla_pool.base) |
| 3641 | free_pages((unsigned long)base->lcla_pool.base, |
| 3642 | base->lcla_pool.pages); |
Jonas Aaberg | 767a967 | 2010-08-09 12:08:34 +0000 | [diff] [blame] | 3643 | |
| 3644 | kfree(base->lcla_pool.base_unaligned); |
| 3645 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3646 | if (base->phy_lcpa) |
| 3647 | release_mem_region(base->phy_lcpa, |
| 3648 | base->lcpa_size); |
| 3649 | if (base->phy_start) |
| 3650 | release_mem_region(base->phy_start, |
| 3651 | base->phy_size); |
| 3652 | if (base->clk) { |
Fabio Baltieri | da2ac56 | 2013-01-07 10:58:35 +0100 | [diff] [blame] | 3653 | clk_disable_unprepare(base->clk); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3654 | clk_put(base->clk); |
| 3655 | } |
| 3656 | |
Narayanan G | 28c7a19 | 2011-11-22 13:56:55 +0530 | [diff] [blame] | 3657 | if (base->lcpa_regulator) { |
| 3658 | regulator_disable(base->lcpa_regulator); |
| 3659 | regulator_put(base->lcpa_regulator); |
| 3660 | } |
| 3661 | |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3662 | kfree(base->lcla_pool.alloc_map); |
| 3663 | kfree(base->lookup_log_chans); |
| 3664 | kfree(base->lookup_phy_chans); |
| 3665 | kfree(base->phy_res); |
| 3666 | kfree(base); |
| 3667 | } |
| 3668 | |
Rabin Vincent | 6db5a8b | 2011-01-25 11:18:09 +0100 | [diff] [blame] | 3669 | d40_err(&pdev->dev, "probe failed\n"); |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3670 | return ret; |
| 3671 | } |
| 3672 | |
| 3673 | static struct platform_driver d40_driver = { |
| 3674 | .driver = { |
| 3675 | .owner = THIS_MODULE, |
| 3676 | .name = D40_NAME, |
Narayanan G | 7fb3e75 | 2011-11-17 17:26:41 +0530 | [diff] [blame] | 3677 | .pm = DMA40_PM_OPS, |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3678 | }, |
| 3679 | }; |
| 3680 | |
Rabin Vincent | cb9ab2d | 2011-01-25 11:18:04 +0100 | [diff] [blame] | 3681 | static int __init stedma40_init(void) |
Linus Walleij | 8d318a5 | 2010-03-30 15:33:42 +0200 | [diff] [blame] | 3682 | { |
| 3683 | return platform_driver_probe(&d40_driver, d40_probe); |
| 3684 | } |
Linus Walleij | a0eb221 | 2011-05-18 14:18:57 +0200 | [diff] [blame] | 3685 | subsys_initcall(stedma40_init); |