Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 1 | /* linux/arch/arm/mach-msm/dma.c |
| 2 | * |
| 3 | * Copyright (C) 2007 Google, Inc. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4 | * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved. |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 5 | * |
| 6 | * This software is licensed under the terms of the GNU General Public |
| 7 | * License version 2, as published by the Free Software Foundation, and |
| 8 | * may be copied, distributed, and modified under those terms. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | */ |
| 16 | |
Arve Hjønnevåg | c554107 | 2009-06-25 17:03:14 -0700 | [diff] [blame] | 17 | #include <linux/clk.h> |
| 18 | #include <linux/err.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 19 | #include <linux/io.h> |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/spinlock.h> |
| 24 | #include <linux/pm_runtime.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 25 | #include <mach/dma.h> |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 26 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | #define MODULE_NAME "msm_dmov" |
| 28 | |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 29 | #define MSM_DMOV_CHANNEL_COUNT 16 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | #define MSM_DMOV_CRCI_COUNT 16 |
| 31 | |
| 32 | enum { |
| 33 | CLK_DIS, |
| 34 | CLK_TO_BE_DIS, |
| 35 | CLK_EN |
| 36 | }; |
| 37 | |
| 38 | struct msm_dmov_ci_conf { |
| 39 | int start; |
| 40 | int end; |
| 41 | int burst; |
| 42 | }; |
| 43 | |
| 44 | struct msm_dmov_crci_conf { |
| 45 | int sd; |
| 46 | int blk_size; |
| 47 | }; |
| 48 | |
| 49 | struct msm_dmov_chan_conf { |
| 50 | int sd; |
| 51 | int block; |
| 52 | int priority; |
| 53 | }; |
| 54 | |
| 55 | struct msm_dmov_conf { |
| 56 | void *base; |
| 57 | struct msm_dmov_crci_conf *crci_conf; |
| 58 | struct msm_dmov_chan_conf *chan_conf; |
| 59 | int channel_active; |
Jeff Ohlstein | 905f1ce | 2011-09-07 18:50:18 -0700 | [diff] [blame^] | 60 | int sd; |
| 61 | size_t sd_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 62 | struct list_head ready_commands[MSM_DMOV_CHANNEL_COUNT]; |
| 63 | struct list_head active_commands[MSM_DMOV_CHANNEL_COUNT]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 64 | spinlock_t lock; |
| 65 | unsigned int irq; |
| 66 | struct clk *clk; |
| 67 | struct clk *pclk; |
| 68 | struct clk *ebiclk; |
| 69 | unsigned int clk_ctl; |
| 70 | struct timer_list timer; |
| 71 | }; |
| 72 | |
| 73 | static void msm_dmov_clock_timer(unsigned long); |
| 74 | static int msm_dmov_clk_toggle(int, int); |
| 75 | |
| 76 | #ifdef CONFIG_ARCH_MSM8X60 |
| 77 | |
| 78 | #define DMOV_CHANNEL_DEFAULT_CONF { .sd = 1, .block = 0, .priority = 0 } |
| 79 | #define DMOV_CHANNEL_MODEM_CONF { .sd = 3, .block = 0, .priority = 0 } |
| 80 | #define DMOV_CHANNEL_CONF(secd, blk, pri) \ |
| 81 | { .sd = secd, .block = blk, .priority = pri } |
| 82 | |
| 83 | static struct msm_dmov_chan_conf adm0_chan_conf[] = { |
| 84 | DMOV_CHANNEL_DEFAULT_CONF, |
| 85 | DMOV_CHANNEL_DEFAULT_CONF, |
| 86 | DMOV_CHANNEL_DEFAULT_CONF, |
| 87 | DMOV_CHANNEL_DEFAULT_CONF, |
| 88 | DMOV_CHANNEL_DEFAULT_CONF, |
| 89 | DMOV_CHANNEL_DEFAULT_CONF, |
| 90 | DMOV_CHANNEL_DEFAULT_CONF, |
| 91 | DMOV_CHANNEL_DEFAULT_CONF, |
| 92 | DMOV_CHANNEL_DEFAULT_CONF, |
| 93 | DMOV_CHANNEL_DEFAULT_CONF, |
| 94 | DMOV_CHANNEL_MODEM_CONF, |
| 95 | DMOV_CHANNEL_MODEM_CONF, |
| 96 | DMOV_CHANNEL_MODEM_CONF, |
| 97 | DMOV_CHANNEL_MODEM_CONF, |
| 98 | DMOV_CHANNEL_MODEM_CONF, |
| 99 | DMOV_CHANNEL_DEFAULT_CONF, |
| 100 | }; |
| 101 | |
| 102 | static struct msm_dmov_chan_conf adm1_chan_conf[] = { |
| 103 | DMOV_CHANNEL_DEFAULT_CONF, |
| 104 | DMOV_CHANNEL_DEFAULT_CONF, |
| 105 | DMOV_CHANNEL_DEFAULT_CONF, |
| 106 | DMOV_CHANNEL_DEFAULT_CONF, |
| 107 | DMOV_CHANNEL_DEFAULT_CONF, |
| 108 | DMOV_CHANNEL_DEFAULT_CONF, |
| 109 | DMOV_CHANNEL_DEFAULT_CONF, |
| 110 | DMOV_CHANNEL_DEFAULT_CONF, |
| 111 | DMOV_CHANNEL_DEFAULT_CONF, |
| 112 | DMOV_CHANNEL_DEFAULT_CONF, |
| 113 | DMOV_CHANNEL_MODEM_CONF, |
| 114 | DMOV_CHANNEL_MODEM_CONF, |
| 115 | DMOV_CHANNEL_MODEM_CONF, |
| 116 | DMOV_CHANNEL_MODEM_CONF, |
| 117 | DMOV_CHANNEL_MODEM_CONF, |
| 118 | DMOV_CHANNEL_MODEM_CONF, |
| 119 | }; |
| 120 | |
| 121 | #define DMOV_CRCI_DEFAULT_CONF { .sd = 1, .blk_size = 0 } |
| 122 | #define DMOV_CRCI_CONF(secd, blk) { .sd = secd, .blk_size = blk } |
| 123 | |
| 124 | static struct msm_dmov_crci_conf adm0_crci_conf[] = { |
| 125 | DMOV_CRCI_DEFAULT_CONF, |
| 126 | DMOV_CRCI_DEFAULT_CONF, |
| 127 | DMOV_CRCI_DEFAULT_CONF, |
| 128 | DMOV_CRCI_DEFAULT_CONF, |
| 129 | DMOV_CRCI_DEFAULT_CONF, |
| 130 | DMOV_CRCI_DEFAULT_CONF, |
| 131 | DMOV_CRCI_CONF(1, 4), |
| 132 | DMOV_CRCI_DEFAULT_CONF, |
| 133 | DMOV_CRCI_DEFAULT_CONF, |
| 134 | DMOV_CRCI_DEFAULT_CONF, |
| 135 | DMOV_CRCI_DEFAULT_CONF, |
| 136 | DMOV_CRCI_DEFAULT_CONF, |
| 137 | DMOV_CRCI_DEFAULT_CONF, |
| 138 | DMOV_CRCI_DEFAULT_CONF, |
| 139 | DMOV_CRCI_DEFAULT_CONF, |
| 140 | DMOV_CRCI_DEFAULT_CONF, |
| 141 | }; |
| 142 | |
| 143 | static struct msm_dmov_crci_conf adm1_crci_conf[] = { |
| 144 | DMOV_CRCI_DEFAULT_CONF, |
| 145 | DMOV_CRCI_CONF(1, 1), |
| 146 | DMOV_CRCI_CONF(1, 1), |
| 147 | DMOV_CRCI_DEFAULT_CONF, |
| 148 | DMOV_CRCI_CONF(1, 1), |
| 149 | DMOV_CRCI_CONF(1, 1), |
| 150 | DMOV_CRCI_DEFAULT_CONF, |
| 151 | DMOV_CRCI_DEFAULT_CONF, |
| 152 | DMOV_CRCI_DEFAULT_CONF, |
| 153 | DMOV_CRCI_DEFAULT_CONF, |
| 154 | DMOV_CRCI_DEFAULT_CONF, |
| 155 | DMOV_CRCI_DEFAULT_CONF, |
| 156 | DMOV_CRCI_DEFAULT_CONF, |
| 157 | DMOV_CRCI_DEFAULT_CONF, |
| 158 | DMOV_CRCI_CONF(1, 1), |
| 159 | DMOV_CRCI_DEFAULT_CONF, |
| 160 | }; |
| 161 | |
| 162 | static struct msm_dmov_conf dmov_conf[] = { |
| 163 | { |
| 164 | .crci_conf = adm0_crci_conf, |
| 165 | .chan_conf = adm0_chan_conf, |
| 166 | .lock = __SPIN_LOCK_UNLOCKED(dmov_lock), |
| 167 | .clk_ctl = CLK_DIS, |
| 168 | .timer = TIMER_INITIALIZER(msm_dmov_clock_timer, 0, 0), |
| 169 | }, { |
| 170 | .crci_conf = adm1_crci_conf, |
| 171 | .chan_conf = adm1_chan_conf, |
| 172 | .lock = __SPIN_LOCK_UNLOCKED(dmov_lock), |
| 173 | .clk_ctl = CLK_DIS, |
| 174 | .timer = TIMER_INITIALIZER(msm_dmov_clock_timer, 0, 1), |
| 175 | } |
| 176 | }; |
| 177 | #else |
| 178 | static struct msm_dmov_conf dmov_conf[] = { |
| 179 | { |
| 180 | .crci_conf = NULL, |
| 181 | .chan_conf = NULL, |
| 182 | .lock = __SPIN_LOCK_UNLOCKED(dmov_lock), |
| 183 | .clk_ctl = CLK_DIS, |
| 184 | .timer = TIMER_INITIALIZER(msm_dmov_clock_timer, 0, 0), |
| 185 | } |
| 186 | }; |
| 187 | #endif |
| 188 | |
| 189 | #define MSM_DMOV_ID_COUNT (MSM_DMOV_CHANNEL_COUNT * ARRAY_SIZE(dmov_conf)) |
Jeff Ohlstein | 905f1ce | 2011-09-07 18:50:18 -0700 | [diff] [blame^] | 190 | #define DMOV_REG(name, adm) ((name) + (dmov_conf[adm].base) +\ |
| 191 | (dmov_conf[adm].sd * dmov_conf[adm].sd_size)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 192 | #define DMOV_ID_TO_ADM(id) ((id) / MSM_DMOV_CHANNEL_COUNT) |
| 193 | #define DMOV_ID_TO_CHAN(id) ((id) % MSM_DMOV_CHANNEL_COUNT) |
| 194 | #define DMOV_CHAN_ADM_TO_ID(ch, adm) ((ch) + (adm) * MSM_DMOV_CHANNEL_COUNT) |
| 195 | |
| 196 | #ifdef CONFIG_MSM_ADM3 |
| 197 | #define DMOV_IRQ_TO_ADM(irq) \ |
| 198 | ({ \ |
| 199 | typeof(irq) _irq = irq; \ |
| 200 | ((_irq == INT_ADM1_MASTER) || (_irq == INT_ADM1_AARM)); \ |
| 201 | }) |
| 202 | #else |
| 203 | #define DMOV_IRQ_TO_ADM(irq) 0 |
| 204 | #endif |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 205 | |
| 206 | enum { |
| 207 | MSM_DMOV_PRINT_ERRORS = 1, |
| 208 | MSM_DMOV_PRINT_IO = 2, |
| 209 | MSM_DMOV_PRINT_FLOW = 4 |
| 210 | }; |
| 211 | |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 212 | unsigned int msm_dmov_print_mask = MSM_DMOV_PRINT_ERRORS; |
| 213 | |
| 214 | #define MSM_DMOV_DPRINTF(mask, format, args...) \ |
| 215 | do { \ |
| 216 | if ((mask) & msm_dmov_print_mask) \ |
| 217 | printk(KERN_ERR format, args); \ |
| 218 | } while (0) |
| 219 | #define PRINT_ERROR(format, args...) \ |
| 220 | MSM_DMOV_DPRINTF(MSM_DMOV_PRINT_ERRORS, format, args); |
| 221 | #define PRINT_IO(format, args...) \ |
| 222 | MSM_DMOV_DPRINTF(MSM_DMOV_PRINT_IO, format, args); |
| 223 | #define PRINT_FLOW(format, args...) \ |
| 224 | MSM_DMOV_DPRINTF(MSM_DMOV_PRINT_FLOW, format, args); |
| 225 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 226 | static int msm_dmov_clk_toggle(int adm, int on) |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 227 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 228 | int ret = 0; |
| 229 | |
| 230 | if (on) { |
| 231 | ret = clk_enable(dmov_conf[adm].clk); |
| 232 | if (ret) |
| 233 | goto err; |
| 234 | if (dmov_conf[adm].pclk) { |
| 235 | ret = clk_enable(dmov_conf[adm].pclk); |
| 236 | if (ret) { |
| 237 | clk_disable(dmov_conf[adm].clk); |
| 238 | goto err; |
| 239 | } |
| 240 | } |
| 241 | if (dmov_conf[adm].ebiclk) { |
| 242 | ret = clk_enable(dmov_conf[adm].ebiclk); |
| 243 | if (ret) { |
| 244 | if (dmov_conf[adm].pclk) |
| 245 | clk_disable(dmov_conf[adm].pclk); |
| 246 | clk_disable(dmov_conf[adm].clk); |
| 247 | } |
| 248 | } |
| 249 | } else { |
| 250 | clk_disable(dmov_conf[adm].clk); |
| 251 | if (dmov_conf[adm].pclk) |
| 252 | clk_disable(dmov_conf[adm].pclk); |
| 253 | if (dmov_conf[adm].ebiclk) |
| 254 | clk_disable(dmov_conf[adm].ebiclk); |
| 255 | } |
| 256 | err: |
| 257 | return ret; |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 260 | static void msm_dmov_clock_timer(unsigned long adm) |
| 261 | { |
| 262 | unsigned long irq_flags; |
| 263 | spin_lock_irqsave(&dmov_conf[adm].lock, irq_flags); |
| 264 | if (dmov_conf[adm].clk_ctl == CLK_TO_BE_DIS) { |
| 265 | BUG_ON(dmov_conf[adm].channel_active); |
| 266 | msm_dmov_clk_toggle(adm, 0); |
| 267 | dmov_conf[adm].clk_ctl = CLK_DIS; |
| 268 | } |
| 269 | spin_unlock_irqrestore(&dmov_conf[adm].lock, irq_flags); |
| 270 | } |
| 271 | |
| 272 | void msm_dmov_stop_cmd(unsigned id, struct msm_dmov_cmd *cmd, int graceful) |
| 273 | { |
| 274 | int adm = DMOV_ID_TO_ADM(id); |
| 275 | int ch = DMOV_ID_TO_CHAN(id); |
| 276 | writel_relaxed((graceful << 31), DMOV_REG(DMOV_FLUSH0(ch), adm)); |
| 277 | wmb(); |
| 278 | } |
| 279 | EXPORT_SYMBOL(msm_dmov_stop_cmd); |
| 280 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 281 | void msm_dmov_enqueue_cmd_ext(unsigned id, struct msm_dmov_cmd *cmd) |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 282 | { |
| 283 | unsigned long irq_flags; |
| 284 | unsigned int status; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 285 | int adm = DMOV_ID_TO_ADM(id); |
| 286 | int ch = DMOV_ID_TO_CHAN(id); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 287 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 288 | spin_lock_irqsave(&dmov_conf[adm].lock, irq_flags); |
| 289 | if (dmov_conf[adm].clk_ctl == CLK_DIS) |
| 290 | msm_dmov_clk_toggle(adm, 1); |
| 291 | else if (dmov_conf[adm].clk_ctl == CLK_TO_BE_DIS) |
| 292 | del_timer(&dmov_conf[adm].timer); |
| 293 | dmov_conf[adm].clk_ctl = CLK_EN; |
| 294 | |
| 295 | status = readl_relaxed(DMOV_REG(DMOV_STATUS(ch), adm)); |
Jeff Ohlstein | dc39f97 | 2011-09-02 13:55:16 -0700 | [diff] [blame] | 296 | if (status & DMOV_STATUS_CMD_PTR_RDY) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 297 | PRINT_IO("msm_dmov_enqueue_cmd(%d), start command, status %x\n", |
| 298 | id, status); |
| 299 | if (cmd->exec_func) |
| 300 | cmd->exec_func(cmd); |
| 301 | list_add_tail(&cmd->list, &dmov_conf[adm].active_commands[ch]); |
| 302 | if (!dmov_conf[adm].channel_active) |
| 303 | enable_irq(dmov_conf[adm].irq); |
| 304 | dmov_conf[adm].channel_active |= 1U << ch; |
| 305 | PRINT_IO("Writing %x exactly to register", cmd->cmdptr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 306 | writel_relaxed(cmd->cmdptr, DMOV_REG(DMOV_CMD_PTR(ch), adm)); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 307 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 308 | if (!dmov_conf[adm].channel_active) { |
| 309 | dmov_conf[adm].clk_ctl = CLK_TO_BE_DIS; |
| 310 | mod_timer(&dmov_conf[adm].timer, jiffies + HZ); |
| 311 | } |
Jeff Ohlstein | dc39f97 | 2011-09-02 13:55:16 -0700 | [diff] [blame] | 312 | if (list_empty(&dmov_conf[adm].active_commands[ch])) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 313 | PRINT_ERROR("msm_dmov_enqueue_cmd_ext(%d), stalled, " |
| 314 | "status %x\n", id, status); |
| 315 | PRINT_IO("msm_dmov_enqueue_cmd(%d), enqueue command, status " |
| 316 | "%x\n", id, status); |
| 317 | list_add_tail(&cmd->list, &dmov_conf[adm].ready_commands[ch]); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 318 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 319 | spin_unlock_irqrestore(&dmov_conf[adm].lock, irq_flags); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 320 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 321 | EXPORT_SYMBOL(msm_dmov_enqueue_cmd_ext); |
| 322 | |
| 323 | void msm_dmov_enqueue_cmd(unsigned id, struct msm_dmov_cmd *cmd) |
| 324 | { |
| 325 | /* Disable callback function (for backwards compatibility) */ |
| 326 | cmd->exec_func = NULL; |
| 327 | |
| 328 | msm_dmov_enqueue_cmd_ext(id, cmd); |
| 329 | } |
| 330 | EXPORT_SYMBOL(msm_dmov_enqueue_cmd); |
| 331 | |
| 332 | void msm_dmov_flush(unsigned int id) |
| 333 | { |
| 334 | unsigned long irq_flags; |
| 335 | int ch = DMOV_ID_TO_CHAN(id); |
| 336 | int adm = DMOV_ID_TO_ADM(id); |
| 337 | spin_lock_irqsave(&dmov_conf[adm].lock, irq_flags); |
| 338 | /* XXX not checking if flush cmd sent already */ |
| 339 | if (!list_empty(&dmov_conf[adm].active_commands[ch])) { |
| 340 | PRINT_IO("msm_dmov_flush(%d), send flush cmd\n", id); |
| 341 | writel_relaxed(DMOV_FLUSH_TYPE, DMOV_REG(DMOV_FLUSH0(ch), adm)); |
| 342 | } |
| 343 | /* spin_unlock_irqrestore has the necessary barrier */ |
| 344 | spin_unlock_irqrestore(&dmov_conf[adm].lock, irq_flags); |
| 345 | } |
| 346 | EXPORT_SYMBOL(msm_dmov_flush); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 347 | |
| 348 | struct msm_dmov_exec_cmdptr_cmd { |
| 349 | struct msm_dmov_cmd dmov_cmd; |
| 350 | struct completion complete; |
| 351 | unsigned id; |
| 352 | unsigned int result; |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 353 | struct msm_dmov_errdata err; |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 354 | }; |
| 355 | |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 356 | static void |
| 357 | dmov_exec_cmdptr_complete_func(struct msm_dmov_cmd *_cmd, |
| 358 | unsigned int result, |
| 359 | struct msm_dmov_errdata *err) |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 360 | { |
| 361 | struct msm_dmov_exec_cmdptr_cmd *cmd = container_of(_cmd, struct msm_dmov_exec_cmdptr_cmd, dmov_cmd); |
| 362 | cmd->result = result; |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 363 | if (result != 0x80000002 && err) |
| 364 | memcpy(&cmd->err, err, sizeof(struct msm_dmov_errdata)); |
| 365 | |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 366 | complete(&cmd->complete); |
| 367 | } |
| 368 | |
Jeff Ohlstein | dc39f97 | 2011-09-02 13:55:16 -0700 | [diff] [blame] | 369 | int msm_dmov_exec_cmd(unsigned id, unsigned int cmdptr) |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 370 | { |
| 371 | struct msm_dmov_exec_cmdptr_cmd cmd; |
| 372 | |
| 373 | PRINT_FLOW("dmov_exec_cmdptr(%d, %x)\n", id, cmdptr); |
| 374 | |
| 375 | cmd.dmov_cmd.cmdptr = cmdptr; |
| 376 | cmd.dmov_cmd.complete_func = dmov_exec_cmdptr_complete_func; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 377 | cmd.dmov_cmd.exec_func = NULL; |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 378 | cmd.id = id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 379 | cmd.result = 0; |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 380 | init_completion(&cmd.complete); |
| 381 | |
| 382 | msm_dmov_enqueue_cmd(id, &cmd.dmov_cmd); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 383 | wait_for_completion_io(&cmd.complete); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 384 | |
| 385 | if (cmd.result != 0x80000002) { |
| 386 | PRINT_ERROR("dmov_exec_cmdptr(%d): ERROR, result: %x\n", id, cmd.result); |
| 387 | PRINT_ERROR("dmov_exec_cmdptr(%d): flush: %x %x %x %x\n", |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 388 | id, cmd.err.flush[0], cmd.err.flush[1], cmd.err.flush[2], cmd.err.flush[3]); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 389 | return -EIO; |
| 390 | } |
| 391 | PRINT_FLOW("dmov_exec_cmdptr(%d, %x) done\n", id, cmdptr); |
| 392 | return 0; |
| 393 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 394 | EXPORT_SYMBOL(msm_dmov_exec_cmd); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 395 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 396 | static void fill_errdata(struct msm_dmov_errdata *errdata, int ch, int adm) |
| 397 | { |
| 398 | errdata->flush[0] = readl_relaxed(DMOV_REG(DMOV_FLUSH0(ch), adm)); |
| 399 | errdata->flush[1] = readl_relaxed(DMOV_REG(DMOV_FLUSH1(ch), adm)); |
| 400 | errdata->flush[2] = readl_relaxed(DMOV_REG(DMOV_FLUSH2(ch), adm)); |
| 401 | errdata->flush[3] = readl_relaxed(DMOV_REG(DMOV_FLUSH3(ch), adm)); |
| 402 | errdata->flush[4] = readl_relaxed(DMOV_REG(DMOV_FLUSH4(ch), adm)); |
| 403 | errdata->flush[5] = readl_relaxed(DMOV_REG(DMOV_FLUSH5(ch), adm)); |
| 404 | } |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 405 | |
| 406 | static irqreturn_t msm_datamover_irq_handler(int irq, void *dev_id) |
| 407 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 408 | unsigned int int_status; |
| 409 | unsigned int mask; |
| 410 | unsigned int id; |
| 411 | unsigned int ch; |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 412 | unsigned long irq_flags; |
| 413 | unsigned int ch_status; |
| 414 | unsigned int ch_result; |
Jeff Ohlstein | 67b8e4c | 2011-09-06 18:13:15 -0700 | [diff] [blame] | 415 | unsigned int valid = 0; |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 416 | struct msm_dmov_cmd *cmd; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 417 | int adm = DMOV_IRQ_TO_ADM(irq); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 418 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 419 | spin_lock_irqsave(&dmov_conf[adm].lock, irq_flags); |
| 420 | /* read and clear isr */ |
| 421 | int_status = readl_relaxed(DMOV_REG(DMOV_ISR, adm)); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 422 | PRINT_FLOW("msm_datamover_irq_handler: DMOV_ISR %x\n", int_status); |
| 423 | |
| 424 | while (int_status) { |
| 425 | mask = int_status & -int_status; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 426 | ch = fls(mask) - 1; |
| 427 | id = DMOV_CHAN_ADM_TO_ID(ch, adm); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 428 | PRINT_FLOW("msm_datamover_irq_handler %08x %08x id %d\n", int_status, mask, id); |
| 429 | int_status &= ~mask; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 430 | ch_status = readl_relaxed(DMOV_REG(DMOV_STATUS(ch), adm)); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 431 | if (!(ch_status & DMOV_STATUS_RSLT_VALID)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 432 | PRINT_FLOW("msm_datamover_irq_handler id %d, " |
| 433 | "result not valid %x\n", id, ch_status); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 434 | continue; |
| 435 | } |
| 436 | do { |
Jeff Ohlstein | 67b8e4c | 2011-09-06 18:13:15 -0700 | [diff] [blame] | 437 | valid = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 438 | ch_result = readl_relaxed(DMOV_REG(DMOV_RSLT(ch), adm)); |
| 439 | if (list_empty(&dmov_conf[adm].active_commands[ch])) { |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 440 | PRINT_ERROR("msm_datamover_irq_handler id %d, got result " |
| 441 | "with no active command, status %x, result %x\n", |
| 442 | id, ch_status, ch_result); |
| 443 | cmd = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 444 | } else { |
| 445 | cmd = list_entry(dmov_conf[adm]. |
| 446 | active_commands[ch].next, typeof(*cmd), |
| 447 | list); |
| 448 | } |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 449 | PRINT_FLOW("msm_datamover_irq_handler id %d, status %x, result %x\n", id, ch_status, ch_result); |
| 450 | if (ch_result & DMOV_RSLT_DONE) { |
| 451 | PRINT_FLOW("msm_datamover_irq_handler id %d, status %x\n", |
| 452 | id, ch_status); |
| 453 | PRINT_IO("msm_datamover_irq_handler id %d, got result " |
| 454 | "for %p, result %x\n", id, cmd, ch_result); |
| 455 | if (cmd) { |
| 456 | list_del(&cmd->list); |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 457 | cmd->complete_func(cmd, ch_result, NULL); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | if (ch_result & DMOV_RSLT_FLUSH) { |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 461 | struct msm_dmov_errdata errdata; |
| 462 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 463 | fill_errdata(&errdata, ch, adm); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 464 | PRINT_FLOW("msm_datamover_irq_handler id %d, status %x\n", id, ch_status); |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 465 | PRINT_FLOW("msm_datamover_irq_handler id %d, flush, result %x, flush0 %x\n", id, ch_result, errdata.flush[0]); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 466 | if (cmd) { |
| 467 | list_del(&cmd->list); |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 468 | cmd->complete_func(cmd, ch_result, &errdata); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | if (ch_result & DMOV_RSLT_ERROR) { |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 472 | struct msm_dmov_errdata errdata; |
| 473 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 474 | fill_errdata(&errdata, ch, adm); |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 475 | |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 476 | PRINT_ERROR("msm_datamover_irq_handler id %d, status %x\n", id, ch_status); |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 477 | PRINT_ERROR("msm_datamover_irq_handler id %d, error, result %x, flush0 %x\n", id, ch_result, errdata.flush[0]); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 478 | if (cmd) { |
| 479 | list_del(&cmd->list); |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 480 | cmd->complete_func(cmd, ch_result, &errdata); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 481 | } |
| 482 | /* this does not seem to work, once we get an error */ |
| 483 | /* the datamover will no longer accept commands */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 484 | writel_relaxed(0, DMOV_REG(DMOV_FLUSH0(ch), |
| 485 | adm)); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 486 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 487 | rmb(); |
| 488 | ch_status = readl_relaxed(DMOV_REG(DMOV_STATUS(ch), |
| 489 | adm)); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 490 | PRINT_FLOW("msm_datamover_irq_handler id %d, status %x\n", id, ch_status); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 491 | if ((ch_status & DMOV_STATUS_CMD_PTR_RDY) && |
| 492 | !list_empty(&dmov_conf[adm].ready_commands[ch])) { |
| 493 | cmd = list_entry(dmov_conf[adm]. |
| 494 | ready_commands[ch].next, typeof(*cmd), |
| 495 | list); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 496 | list_del(&cmd->list); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 497 | if (cmd->exec_func) |
| 498 | cmd->exec_func(cmd); |
| 499 | list_add_tail(&cmd->list, |
| 500 | &dmov_conf[adm].active_commands[ch]); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 501 | PRINT_FLOW("msm_datamover_irq_handler id %d, start command\n", id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 502 | writel_relaxed(cmd->cmdptr, |
| 503 | DMOV_REG(DMOV_CMD_PTR(ch), adm)); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 504 | } |
| 505 | } while (ch_status & DMOV_STATUS_RSLT_VALID); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 506 | if (list_empty(&dmov_conf[adm].active_commands[ch]) && |
| 507 | list_empty(&dmov_conf[adm].ready_commands[ch])) |
| 508 | dmov_conf[adm].channel_active &= ~(1U << ch); |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 509 | PRINT_FLOW("msm_datamover_irq_handler id %d, status %x\n", id, ch_status); |
| 510 | } |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 511 | |
Jeff Ohlstein | 67b8e4c | 2011-09-06 18:13:15 -0700 | [diff] [blame] | 512 | if (!dmov_conf[adm].channel_active && valid) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 513 | disable_irq_nosync(dmov_conf[adm].irq); |
| 514 | dmov_conf[adm].clk_ctl = CLK_TO_BE_DIS; |
| 515 | mod_timer(&dmov_conf[adm].timer, jiffies + HZ); |
Arve Hjønnevåg | c554107 | 2009-06-25 17:03:14 -0700 | [diff] [blame] | 516 | } |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 517 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 518 | spin_unlock_irqrestore(&dmov_conf[adm].lock, irq_flags); |
Jeff Ohlstein | 67b8e4c | 2011-09-06 18:13:15 -0700 | [diff] [blame] | 519 | return valid ? IRQ_HANDLED : IRQ_NONE; |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 520 | } |
| 521 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 522 | static int msm_dmov_suspend_late(struct device *dev) |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 523 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 524 | unsigned long irq_flags; |
| 525 | struct platform_device *pdev = to_platform_device(dev); |
| 526 | int adm = (pdev->id >= 0) ? pdev->id : 0; |
| 527 | spin_lock_irqsave(&dmov_conf[adm].lock, irq_flags); |
| 528 | if (dmov_conf[adm].clk_ctl == CLK_TO_BE_DIS) { |
| 529 | BUG_ON(dmov_conf[adm].channel_active); |
| 530 | del_timer(&dmov_conf[adm].timer); |
| 531 | msm_dmov_clk_toggle(adm, 0); |
| 532 | dmov_conf[adm].clk_ctl = CLK_DIS; |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 533 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 534 | spin_unlock_irqrestore(&dmov_conf[adm].lock, irq_flags); |
Brian Swetland | 8a0f6f1 | 2008-09-10 14:58:25 -0700 | [diff] [blame] | 535 | return 0; |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 536 | } |
| 537 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 538 | static int msm_dmov_runtime_suspend(struct device *dev) |
| 539 | { |
| 540 | dev_dbg(dev, "pm_runtime: suspending...\n"); |
| 541 | return 0; |
| 542 | } |
Arve Hjønnevåg | bfe645a | 2007-11-26 04:12:29 -0800 | [diff] [blame] | 543 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 544 | static int msm_dmov_runtime_resume(struct device *dev) |
| 545 | { |
| 546 | dev_dbg(dev, "pm_runtime: resuming...\n"); |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | static int msm_dmov_runtime_idle(struct device *dev) |
| 551 | { |
| 552 | dev_dbg(dev, "pm_runtime: idling...\n"); |
| 553 | return 0; |
| 554 | } |
| 555 | |
| 556 | static struct dev_pm_ops msm_dmov_dev_pm_ops = { |
| 557 | .runtime_suspend = msm_dmov_runtime_suspend, |
| 558 | .runtime_resume = msm_dmov_runtime_resume, |
| 559 | .runtime_idle = msm_dmov_runtime_idle, |
| 560 | .suspend = msm_dmov_suspend_late, |
| 561 | }; |
| 562 | |
| 563 | static int msm_dmov_init_clocks(struct platform_device *pdev) |
| 564 | { |
| 565 | int adm = (pdev->id >= 0) ? pdev->id : 0; |
| 566 | int ret; |
| 567 | |
Matt Wagantall | e1a8606 | 2011-08-18 17:46:10 -0700 | [diff] [blame] | 568 | dmov_conf[adm].clk = clk_get(&pdev->dev, "core_clk"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 569 | if (IS_ERR(dmov_conf[adm].clk)) { |
| 570 | printk(KERN_ERR "%s: Error getting adm_clk\n", __func__); |
| 571 | dmov_conf[adm].clk = NULL; |
| 572 | return -ENOENT; |
| 573 | } |
| 574 | |
Matt Wagantall | e1a8606 | 2011-08-18 17:46:10 -0700 | [diff] [blame] | 575 | dmov_conf[adm].pclk = clk_get(&pdev->dev, "iface_clk"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 576 | if (IS_ERR(dmov_conf[adm].pclk)) { |
| 577 | dmov_conf[adm].pclk = NULL; |
| 578 | /* pclk not present on all SoCs, don't bail on failure */ |
| 579 | } |
| 580 | |
Matt Wagantall | e1a8606 | 2011-08-18 17:46:10 -0700 | [diff] [blame] | 581 | dmov_conf[adm].ebiclk = clk_get(&pdev->dev, "mem_clk"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 582 | if (IS_ERR(dmov_conf[adm].ebiclk)) { |
| 583 | dmov_conf[adm].ebiclk = NULL; |
| 584 | /* ebiclk not present on all SoCs, don't bail on failure */ |
| 585 | } else { |
| 586 | ret = clk_set_rate(dmov_conf[adm].ebiclk, 27000000); |
| 587 | if (ret) |
| 588 | return -ENOENT; |
| 589 | } |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | static void config_datamover(int adm) |
| 595 | { |
| 596 | #ifdef CONFIG_MSM_ADM3 |
| 597 | int i; |
| 598 | for (i = 0; i < MSM_DMOV_CHANNEL_COUNT; i++) { |
| 599 | struct msm_dmov_chan_conf *chan_conf = |
| 600 | dmov_conf[adm].chan_conf; |
| 601 | unsigned conf; |
| 602 | /* Only configure scorpion channels */ |
| 603 | if (chan_conf[i].sd <= 1) { |
| 604 | conf = readl_relaxed(DMOV_REG(DMOV_CONF(i), adm)); |
| 605 | conf &= ~DMOV_CONF_SD(7); |
| 606 | conf |= DMOV_CONF_SD(chan_conf[i].sd); |
| 607 | writel_relaxed(conf | DMOV_CONF_SHADOW_EN, |
| 608 | DMOV_REG(DMOV_CONF(i), adm)); |
| 609 | } |
| 610 | } |
| 611 | for (i = 0; i < MSM_DMOV_CRCI_COUNT; i++) { |
| 612 | struct msm_dmov_crci_conf *crci_conf = |
| 613 | dmov_conf[adm].crci_conf; |
| 614 | |
| 615 | writel_relaxed(DMOV_CRCI_CTL_BLK_SZ(crci_conf[i].blk_size), |
| 616 | DMOV_REG(DMOV_CRCI_CTL(i), adm)); |
| 617 | } |
| 618 | #endif |
| 619 | } |
| 620 | |
| 621 | static int msm_dmov_probe(struct platform_device *pdev) |
| 622 | { |
| 623 | int adm = (pdev->id >= 0) ? pdev->id : 0; |
| 624 | int i; |
| 625 | int ret; |
Jeff Ohlstein | 905f1ce | 2011-09-07 18:50:18 -0700 | [diff] [blame^] | 626 | struct msm_dmov_pdata *pdata = pdev->dev.platform_data; |
| 627 | struct resource *irqres = |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 628 | platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
Jeff Ohlstein | 905f1ce | 2011-09-07 18:50:18 -0700 | [diff] [blame^] | 629 | struct resource *mres = |
| 630 | platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 631 | |
Jeff Ohlstein | 905f1ce | 2011-09-07 18:50:18 -0700 | [diff] [blame^] | 632 | if (pdata) { |
| 633 | dmov_conf[adm].sd = pdata->sd; |
| 634 | dmov_conf[adm].sd_size = pdata->sd_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 635 | } |
Jeff Ohlstein | 905f1ce | 2011-09-07 18:50:18 -0700 | [diff] [blame^] | 636 | if (!dmov_conf[adm].sd_size) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 637 | return -ENXIO; |
| 638 | |
Jeff Ohlstein | 905f1ce | 2011-09-07 18:50:18 -0700 | [diff] [blame^] | 639 | if (!irqres || !irqres->start) |
| 640 | return -ENXIO; |
| 641 | dmov_conf[adm].irq = irqres->start; |
| 642 | |
| 643 | if (!mres || !mres->start) |
| 644 | return -ENXIO; |
| 645 | dmov_conf[adm].base = ioremap_nocache(mres->start, resource_size(mres)); |
| 646 | if (!dmov_conf[adm].base) |
| 647 | return -ENOMEM; |
| 648 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 649 | ret = request_irq(dmov_conf[adm].irq, msm_datamover_irq_handler, |
| 650 | 0, "msmdatamover", NULL); |
| 651 | if (ret) { |
| 652 | PRINT_ERROR("Requesting ADM%d irq %d failed\n", adm, |
| 653 | dmov_conf[adm].irq); |
Jeff Ohlstein | 905f1ce | 2011-09-07 18:50:18 -0700 | [diff] [blame^] | 654 | goto out_map; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 655 | } |
| 656 | disable_irq(dmov_conf[adm].irq); |
| 657 | ret = msm_dmov_init_clocks(pdev); |
| 658 | if (ret) { |
| 659 | PRINT_ERROR("Requesting ADM%d clocks failed\n", adm); |
Jeff Ohlstein | 905f1ce | 2011-09-07 18:50:18 -0700 | [diff] [blame^] | 660 | goto out_irq; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 661 | } |
Jeff Ohlstein | cdbfc18 | 2011-08-10 12:08:28 -0700 | [diff] [blame] | 662 | ret = msm_dmov_clk_toggle(adm, 1); |
| 663 | if (ret) { |
| 664 | PRINT_ERROR("Enabling ADM%d clocks failed\n", adm); |
Jeff Ohlstein | 905f1ce | 2011-09-07 18:50:18 -0700 | [diff] [blame^] | 665 | goto out_irq; |
Jeff Ohlstein | cdbfc18 | 2011-08-10 12:08:28 -0700 | [diff] [blame] | 666 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 667 | |
| 668 | config_datamover(adm); |
| 669 | for (i = 0; i < MSM_DMOV_CHANNEL_COUNT; i++) { |
| 670 | INIT_LIST_HEAD(&dmov_conf[adm].ready_commands[i]); |
| 671 | INIT_LIST_HEAD(&dmov_conf[adm].active_commands[i]); |
| 672 | |
| 673 | writel_relaxed(DMOV_RSLT_CONF_IRQ_EN |
| 674 | | DMOV_RSLT_CONF_FORCE_FLUSH_RSLT, |
| 675 | DMOV_REG(DMOV_RSLT_CONF(i), adm)); |
| 676 | } |
| 677 | wmb(); |
Jeff Ohlstein | cdbfc18 | 2011-08-10 12:08:28 -0700 | [diff] [blame] | 678 | msm_dmov_clk_toggle(adm, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 679 | return ret; |
Jeff Ohlstein | 905f1ce | 2011-09-07 18:50:18 -0700 | [diff] [blame^] | 680 | out_irq: |
| 681 | free_irq(dmov_conf[adm].irq, NULL); |
| 682 | out_map: |
| 683 | iounmap(dmov_conf[adm].base); |
| 684 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | static struct platform_driver msm_dmov_driver = { |
| 688 | .probe = msm_dmov_probe, |
| 689 | .driver = { |
| 690 | .name = MODULE_NAME, |
| 691 | .owner = THIS_MODULE, |
| 692 | .pm = &msm_dmov_dev_pm_ops, |
| 693 | }, |
| 694 | }; |
| 695 | |
| 696 | /* static int __init */ |
| 697 | static int __init msm_init_datamover(void) |
| 698 | { |
| 699 | int ret; |
| 700 | ret = platform_driver_register(&msm_dmov_driver); |
| 701 | if (ret) |
| 702 | return ret; |
| 703 | return 0; |
| 704 | } |
| 705 | arch_initcall(msm_init_datamover); |