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