Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * driver/dma/coh901318.c |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 ST-Ericsson |
| 5 | * License terms: GNU General Public License (GPL) version 2 |
| 6 | * DMA driver for COH 901 318 |
| 7 | * Author: Per Friden <per.friden@stericsson.com> |
| 8 | */ |
| 9 | |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/kernel.h> /* printk() */ |
| 13 | #include <linux/fs.h> /* everything... */ |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 14 | #include <linux/scatterlist.h> |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 15 | #include <linux/slab.h> /* kmalloc() */ |
| 16 | #include <linux/dmaengine.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/device.h> |
| 19 | #include <linux/irqreturn.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/io.h> |
| 22 | #include <linux/uaccess.h> |
| 23 | #include <linux/debugfs.h> |
Linus Walleij | 9f575d9 | 2013-01-04 10:35:06 +0100 | [diff] [blame^] | 24 | #include <linux/platform_data/dma-coh901318.h> |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 25 | #include <mach/coh901318.h> |
| 26 | |
| 27 | #include "coh901318_lli.h" |
Russell King - ARM Linux | d2ebfb3 | 2012-03-06 22:34:26 +0000 | [diff] [blame] | 28 | #include "dmaengine.h" |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 29 | |
| 30 | #define COHC_2_DEV(cohc) (&cohc->chan.dev->device) |
| 31 | |
| 32 | #ifdef VERBOSE_DEBUG |
| 33 | #define COH_DBG(x) ({ if (1) x; 0; }) |
| 34 | #else |
| 35 | #define COH_DBG(x) ({ if (0) x; 0; }) |
| 36 | #endif |
| 37 | |
| 38 | struct coh901318_desc { |
| 39 | struct dma_async_tx_descriptor desc; |
| 40 | struct list_head node; |
| 41 | struct scatterlist *sg; |
| 42 | unsigned int sg_len; |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 43 | struct coh901318_lli *lli; |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 44 | enum dma_transfer_direction dir; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 45 | unsigned long flags; |
Linus Walleij | b89243d | 2011-07-01 16:47:28 +0200 | [diff] [blame] | 46 | u32 head_config; |
| 47 | u32 head_ctrl; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | struct coh901318_base { |
| 51 | struct device *dev; |
| 52 | void __iomem *virtbase; |
| 53 | struct coh901318_pool pool; |
| 54 | struct powersave pm; |
| 55 | struct dma_device dma_slave; |
| 56 | struct dma_device dma_memcpy; |
| 57 | struct coh901318_chan *chans; |
| 58 | struct coh901318_platform *platform; |
| 59 | }; |
| 60 | |
| 61 | struct coh901318_chan { |
| 62 | spinlock_t lock; |
| 63 | int allocated; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 64 | int id; |
| 65 | int stopped; |
| 66 | |
| 67 | struct work_struct free_work; |
| 68 | struct dma_chan chan; |
| 69 | |
| 70 | struct tasklet_struct tasklet; |
| 71 | |
| 72 | struct list_head active; |
| 73 | struct list_head queue; |
| 74 | struct list_head free; |
| 75 | |
| 76 | unsigned long nbr_active_done; |
| 77 | unsigned long busy; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 78 | |
Linus Walleij | 128f904 | 2010-08-04 13:37:53 +0200 | [diff] [blame] | 79 | u32 runtime_addr; |
| 80 | u32 runtime_ctrl; |
| 81 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 82 | struct coh901318_base *base; |
| 83 | }; |
| 84 | |
| 85 | static void coh901318_list_print(struct coh901318_chan *cohc, |
| 86 | struct coh901318_lli *lli) |
| 87 | { |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 88 | struct coh901318_lli *l = lli; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 89 | int i = 0; |
| 90 | |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 91 | while (l) { |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 92 | dev_vdbg(COHC_2_DEV(cohc), "i %d, lli %p, ctrl 0x%x, src 0x%x" |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 93 | ", dst 0x%x, link 0x%x virt_link_addr 0x%p\n", |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 94 | i, l, l->control, l->src_addr, l->dst_addr, |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 95 | l->link_addr, l->virt_link_addr); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 96 | i++; |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 97 | l = l->virt_link_addr; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | #ifdef CONFIG_DEBUG_FS |
| 102 | |
| 103 | #define COH901318_DEBUGFS_ASSIGN(x, y) (x = y) |
| 104 | |
| 105 | static struct coh901318_base *debugfs_dma_base; |
| 106 | static struct dentry *dma_dentry; |
| 107 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 108 | static int coh901318_debugfs_read(struct file *file, char __user *buf, |
| 109 | size_t count, loff_t *f_pos) |
| 110 | { |
| 111 | u64 started_channels = debugfs_dma_base->pm.started_channels; |
| 112 | int pool_count = debugfs_dma_base->pool.debugfs_pool_counter; |
| 113 | int i; |
| 114 | int ret = 0; |
| 115 | char *dev_buf; |
| 116 | char *tmp; |
| 117 | int dev_size; |
| 118 | |
| 119 | dev_buf = kmalloc(4*1024, GFP_KERNEL); |
| 120 | if (dev_buf == NULL) |
| 121 | goto err_kmalloc; |
| 122 | tmp = dev_buf; |
| 123 | |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 124 | tmp += sprintf(tmp, "DMA -- enabled dma channels\n"); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 125 | |
| 126 | for (i = 0; i < debugfs_dma_base->platform->max_channels; i++) |
| 127 | if (started_channels & (1 << i)) |
| 128 | tmp += sprintf(tmp, "channel %d\n", i); |
| 129 | |
| 130 | tmp += sprintf(tmp, "Pool alloc nbr %d\n", pool_count); |
| 131 | dev_size = tmp - dev_buf; |
| 132 | |
| 133 | /* No more to read if offset != 0 */ |
| 134 | if (*f_pos > dev_size) |
| 135 | goto out; |
| 136 | |
| 137 | if (count > dev_size - *f_pos) |
| 138 | count = dev_size - *f_pos; |
| 139 | |
| 140 | if (copy_to_user(buf, dev_buf + *f_pos, count)) |
| 141 | ret = -EINVAL; |
| 142 | ret = count; |
| 143 | *f_pos += count; |
| 144 | |
| 145 | out: |
| 146 | kfree(dev_buf); |
| 147 | return ret; |
| 148 | |
| 149 | err_kmalloc: |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | static const struct file_operations coh901318_debugfs_status_operations = { |
| 154 | .owner = THIS_MODULE, |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 155 | .open = simple_open, |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 156 | .read = coh901318_debugfs_read, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 157 | .llseek = default_llseek, |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | |
| 161 | static int __init init_coh901318_debugfs(void) |
| 162 | { |
| 163 | |
| 164 | dma_dentry = debugfs_create_dir("dma", NULL); |
| 165 | |
| 166 | (void) debugfs_create_file("status", |
| 167 | S_IFREG | S_IRUGO, |
| 168 | dma_dentry, NULL, |
| 169 | &coh901318_debugfs_status_operations); |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static void __exit exit_coh901318_debugfs(void) |
| 174 | { |
| 175 | debugfs_remove_recursive(dma_dentry); |
| 176 | } |
| 177 | |
| 178 | module_init(init_coh901318_debugfs); |
| 179 | module_exit(exit_coh901318_debugfs); |
| 180 | #else |
| 181 | |
| 182 | #define COH901318_DEBUGFS_ASSIGN(x, y) |
| 183 | |
| 184 | #endif /* CONFIG_DEBUG_FS */ |
| 185 | |
| 186 | static inline struct coh901318_chan *to_coh901318_chan(struct dma_chan *chan) |
| 187 | { |
| 188 | return container_of(chan, struct coh901318_chan, chan); |
| 189 | } |
| 190 | |
| 191 | static inline dma_addr_t |
| 192 | cohc_dev_addr(struct coh901318_chan *cohc) |
| 193 | { |
Linus Walleij | 128f904 | 2010-08-04 13:37:53 +0200 | [diff] [blame] | 194 | /* Runtime supplied address will take precedence */ |
| 195 | if (cohc->runtime_addr) |
| 196 | return cohc->runtime_addr; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 197 | return cohc->base->platform->chan_conf[cohc->id].dev_addr; |
| 198 | } |
| 199 | |
| 200 | static inline const struct coh901318_params * |
| 201 | cohc_chan_param(struct coh901318_chan *cohc) |
| 202 | { |
| 203 | return &cohc->base->platform->chan_conf[cohc->id].param; |
| 204 | } |
| 205 | |
| 206 | static inline const struct coh_dma_channel * |
| 207 | cohc_chan_conf(struct coh901318_chan *cohc) |
| 208 | { |
| 209 | return &cohc->base->platform->chan_conf[cohc->id]; |
| 210 | } |
| 211 | |
| 212 | static void enable_powersave(struct coh901318_chan *cohc) |
| 213 | { |
| 214 | unsigned long flags; |
| 215 | struct powersave *pm = &cohc->base->pm; |
| 216 | |
| 217 | spin_lock_irqsave(&pm->lock, flags); |
| 218 | |
| 219 | pm->started_channels &= ~(1ULL << cohc->id); |
| 220 | |
| 221 | if (!pm->started_channels) { |
| 222 | /* DMA no longer intends to access memory */ |
| 223 | cohc->base->platform->access_memory_state(cohc->base->dev, |
| 224 | false); |
| 225 | } |
| 226 | |
| 227 | spin_unlock_irqrestore(&pm->lock, flags); |
| 228 | } |
| 229 | static void disable_powersave(struct coh901318_chan *cohc) |
| 230 | { |
| 231 | unsigned long flags; |
| 232 | struct powersave *pm = &cohc->base->pm; |
| 233 | |
| 234 | spin_lock_irqsave(&pm->lock, flags); |
| 235 | |
| 236 | if (!pm->started_channels) { |
| 237 | /* DMA intends to access memory */ |
| 238 | cohc->base->platform->access_memory_state(cohc->base->dev, |
| 239 | true); |
| 240 | } |
| 241 | |
| 242 | pm->started_channels |= (1ULL << cohc->id); |
| 243 | |
| 244 | spin_unlock_irqrestore(&pm->lock, flags); |
| 245 | } |
| 246 | |
| 247 | static inline int coh901318_set_ctrl(struct coh901318_chan *cohc, u32 control) |
| 248 | { |
| 249 | int channel = cohc->id; |
| 250 | void __iomem *virtbase = cohc->base->virtbase; |
| 251 | |
| 252 | writel(control, |
| 253 | virtbase + COH901318_CX_CTRL + |
| 254 | COH901318_CX_CTRL_SPACING * channel); |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | static inline int coh901318_set_conf(struct coh901318_chan *cohc, u32 conf) |
| 259 | { |
| 260 | int channel = cohc->id; |
| 261 | void __iomem *virtbase = cohc->base->virtbase; |
| 262 | |
| 263 | writel(conf, |
| 264 | virtbase + COH901318_CX_CFG + |
| 265 | COH901318_CX_CFG_SPACING*channel); |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | |
| 270 | static int coh901318_start(struct coh901318_chan *cohc) |
| 271 | { |
| 272 | u32 val; |
| 273 | int channel = cohc->id; |
| 274 | void __iomem *virtbase = cohc->base->virtbase; |
| 275 | |
| 276 | disable_powersave(cohc); |
| 277 | |
| 278 | val = readl(virtbase + COH901318_CX_CFG + |
| 279 | COH901318_CX_CFG_SPACING * channel); |
| 280 | |
| 281 | /* Enable channel */ |
| 282 | val |= COH901318_CX_CFG_CH_ENABLE; |
| 283 | writel(val, virtbase + COH901318_CX_CFG + |
| 284 | COH901318_CX_CFG_SPACING * channel); |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | static int coh901318_prep_linked_list(struct coh901318_chan *cohc, |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 290 | struct coh901318_lli *lli) |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 291 | { |
| 292 | int channel = cohc->id; |
| 293 | void __iomem *virtbase = cohc->base->virtbase; |
| 294 | |
| 295 | BUG_ON(readl(virtbase + COH901318_CX_STAT + |
| 296 | COH901318_CX_STAT_SPACING*channel) & |
| 297 | COH901318_CX_STAT_ACTIVE); |
| 298 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 299 | writel(lli->src_addr, |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 300 | virtbase + COH901318_CX_SRC_ADDR + |
| 301 | COH901318_CX_SRC_ADDR_SPACING * channel); |
| 302 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 303 | writel(lli->dst_addr, virtbase + |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 304 | COH901318_CX_DST_ADDR + |
| 305 | COH901318_CX_DST_ADDR_SPACING * channel); |
| 306 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 307 | writel(lli->link_addr, virtbase + COH901318_CX_LNK_ADDR + |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 308 | COH901318_CX_LNK_ADDR_SPACING * channel); |
| 309 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 310 | writel(lli->control, virtbase + COH901318_CX_CTRL + |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 311 | COH901318_CX_CTRL_SPACING * channel); |
| 312 | |
| 313 | return 0; |
| 314 | } |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 315 | |
| 316 | static struct coh901318_desc * |
| 317 | coh901318_desc_get(struct coh901318_chan *cohc) |
| 318 | { |
| 319 | struct coh901318_desc *desc; |
| 320 | |
| 321 | if (list_empty(&cohc->free)) { |
| 322 | /* alloc new desc because we're out of used ones |
| 323 | * TODO: alloc a pile of descs instead of just one, |
| 324 | * avoid many small allocations. |
| 325 | */ |
Linus Walleij | b87108a | 2010-03-02 14:17:20 -0700 | [diff] [blame] | 326 | desc = kzalloc(sizeof(struct coh901318_desc), GFP_NOWAIT); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 327 | if (desc == NULL) |
| 328 | goto out; |
| 329 | INIT_LIST_HEAD(&desc->node); |
Linus Walleij | b87108a | 2010-03-02 14:17:20 -0700 | [diff] [blame] | 330 | dma_async_tx_descriptor_init(&desc->desc, &cohc->chan); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 331 | } else { |
| 332 | /* Reuse an old desc. */ |
| 333 | desc = list_first_entry(&cohc->free, |
| 334 | struct coh901318_desc, |
| 335 | node); |
| 336 | list_del(&desc->node); |
Linus Walleij | b87108a | 2010-03-02 14:17:20 -0700 | [diff] [blame] | 337 | /* Initialize it a bit so it's not insane */ |
| 338 | desc->sg = NULL; |
| 339 | desc->sg_len = 0; |
| 340 | desc->desc.callback = NULL; |
| 341 | desc->desc.callback_param = NULL; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | out: |
| 345 | return desc; |
| 346 | } |
| 347 | |
| 348 | static void |
| 349 | coh901318_desc_free(struct coh901318_chan *cohc, struct coh901318_desc *cohd) |
| 350 | { |
| 351 | list_add_tail(&cohd->node, &cohc->free); |
| 352 | } |
| 353 | |
| 354 | /* call with irq lock held */ |
| 355 | static void |
| 356 | coh901318_desc_submit(struct coh901318_chan *cohc, struct coh901318_desc *desc) |
| 357 | { |
| 358 | list_add_tail(&desc->node, &cohc->active); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static struct coh901318_desc * |
| 362 | coh901318_first_active_get(struct coh901318_chan *cohc) |
| 363 | { |
| 364 | struct coh901318_desc *d; |
| 365 | |
| 366 | if (list_empty(&cohc->active)) |
| 367 | return NULL; |
| 368 | |
| 369 | d = list_first_entry(&cohc->active, |
| 370 | struct coh901318_desc, |
| 371 | node); |
| 372 | return d; |
| 373 | } |
| 374 | |
| 375 | static void |
| 376 | coh901318_desc_remove(struct coh901318_desc *cohd) |
| 377 | { |
| 378 | list_del(&cohd->node); |
| 379 | } |
| 380 | |
| 381 | static void |
| 382 | coh901318_desc_queue(struct coh901318_chan *cohc, struct coh901318_desc *desc) |
| 383 | { |
| 384 | list_add_tail(&desc->node, &cohc->queue); |
| 385 | } |
| 386 | |
| 387 | static struct coh901318_desc * |
| 388 | coh901318_first_queued(struct coh901318_chan *cohc) |
| 389 | { |
| 390 | struct coh901318_desc *d; |
| 391 | |
| 392 | if (list_empty(&cohc->queue)) |
| 393 | return NULL; |
| 394 | |
| 395 | d = list_first_entry(&cohc->queue, |
| 396 | struct coh901318_desc, |
| 397 | node); |
| 398 | return d; |
| 399 | } |
| 400 | |
Linus Walleij | 84c8447 | 2010-03-04 14:40:30 +0100 | [diff] [blame] | 401 | static inline u32 coh901318_get_bytes_in_lli(struct coh901318_lli *in_lli) |
| 402 | { |
| 403 | struct coh901318_lli *lli = in_lli; |
| 404 | u32 bytes = 0; |
| 405 | |
| 406 | while (lli) { |
| 407 | bytes += lli->control & COH901318_CX_CTRL_TC_VALUE_MASK; |
| 408 | lli = lli->virt_link_addr; |
| 409 | } |
| 410 | return bytes; |
| 411 | } |
| 412 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 413 | /* |
Linus Walleij | 84c8447 | 2010-03-04 14:40:30 +0100 | [diff] [blame] | 414 | * Get the number of bytes left to transfer on this channel, |
| 415 | * it is unwise to call this before stopping the channel for |
| 416 | * absolute measures, but for a rough guess you can still call |
| 417 | * it. |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 418 | */ |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 419 | static u32 coh901318_get_bytes_left(struct dma_chan *chan) |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 420 | { |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 421 | struct coh901318_chan *cohc = to_coh901318_chan(chan); |
Linus Walleij | 84c8447 | 2010-03-04 14:40:30 +0100 | [diff] [blame] | 422 | struct coh901318_desc *cohd; |
| 423 | struct list_head *pos; |
| 424 | unsigned long flags; |
| 425 | u32 left = 0; |
| 426 | int i = 0; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 427 | |
| 428 | spin_lock_irqsave(&cohc->lock, flags); |
| 429 | |
Linus Walleij | 84c8447 | 2010-03-04 14:40:30 +0100 | [diff] [blame] | 430 | /* |
| 431 | * If there are many queued jobs, we iterate and add the |
| 432 | * size of them all. We take a special look on the first |
| 433 | * job though, since it is probably active. |
| 434 | */ |
| 435 | list_for_each(pos, &cohc->active) { |
| 436 | /* |
| 437 | * The first job in the list will be working on the |
| 438 | * hardware. The job can be stopped but still active, |
| 439 | * so that the transfer counter is somewhere inside |
| 440 | * the buffer. |
| 441 | */ |
| 442 | cohd = list_entry(pos, struct coh901318_desc, node); |
| 443 | |
| 444 | if (i == 0) { |
| 445 | struct coh901318_lli *lli; |
| 446 | dma_addr_t ladd; |
| 447 | |
| 448 | /* Read current transfer count value */ |
| 449 | left = readl(cohc->base->virtbase + |
| 450 | COH901318_CX_CTRL + |
| 451 | COH901318_CX_CTRL_SPACING * cohc->id) & |
| 452 | COH901318_CX_CTRL_TC_VALUE_MASK; |
| 453 | |
| 454 | /* See if the transfer is linked... */ |
| 455 | ladd = readl(cohc->base->virtbase + |
| 456 | COH901318_CX_LNK_ADDR + |
| 457 | COH901318_CX_LNK_ADDR_SPACING * |
| 458 | cohc->id) & |
| 459 | ~COH901318_CX_LNK_LINK_IMMEDIATE; |
| 460 | /* Single transaction */ |
| 461 | if (!ladd) |
| 462 | continue; |
| 463 | |
| 464 | /* |
| 465 | * Linked transaction, follow the lli, find the |
| 466 | * currently processing lli, and proceed to the next |
| 467 | */ |
| 468 | lli = cohd->lli; |
| 469 | while (lli && lli->link_addr != ladd) |
| 470 | lli = lli->virt_link_addr; |
| 471 | |
| 472 | if (lli) |
| 473 | lli = lli->virt_link_addr; |
| 474 | |
| 475 | /* |
| 476 | * Follow remaining lli links around to count the total |
| 477 | * number of bytes left |
| 478 | */ |
| 479 | left += coh901318_get_bytes_in_lli(lli); |
| 480 | } else { |
| 481 | left += coh901318_get_bytes_in_lli(cohd->lli); |
| 482 | } |
| 483 | i++; |
| 484 | } |
| 485 | |
| 486 | /* Also count bytes in the queued jobs */ |
| 487 | list_for_each(pos, &cohc->queue) { |
| 488 | cohd = list_entry(pos, struct coh901318_desc, node); |
| 489 | left += coh901318_get_bytes_in_lli(cohd->lli); |
| 490 | } |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 491 | |
| 492 | spin_unlock_irqrestore(&cohc->lock, flags); |
| 493 | |
Linus Walleij | 84c8447 | 2010-03-04 14:40:30 +0100 | [diff] [blame] | 494 | return left; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 495 | } |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 496 | |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 497 | /* |
| 498 | * Pauses a transfer without losing data. Enables power save. |
| 499 | * Use this function in conjunction with coh901318_resume. |
| 500 | */ |
| 501 | static void coh901318_pause(struct dma_chan *chan) |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 502 | { |
| 503 | u32 val; |
| 504 | unsigned long flags; |
| 505 | struct coh901318_chan *cohc = to_coh901318_chan(chan); |
| 506 | int channel = cohc->id; |
| 507 | void __iomem *virtbase = cohc->base->virtbase; |
| 508 | |
| 509 | spin_lock_irqsave(&cohc->lock, flags); |
| 510 | |
| 511 | /* Disable channel in HW */ |
| 512 | val = readl(virtbase + COH901318_CX_CFG + |
| 513 | COH901318_CX_CFG_SPACING * channel); |
| 514 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 515 | /* Stopping infinite transfer */ |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 516 | if ((val & COH901318_CX_CTRL_TC_ENABLE) == 0 && |
| 517 | (val & COH901318_CX_CFG_CH_ENABLE)) |
| 518 | cohc->stopped = 1; |
| 519 | |
| 520 | |
| 521 | val &= ~COH901318_CX_CFG_CH_ENABLE; |
| 522 | /* Enable twice, HW bug work around */ |
| 523 | writel(val, virtbase + COH901318_CX_CFG + |
| 524 | COH901318_CX_CFG_SPACING * channel); |
| 525 | writel(val, virtbase + COH901318_CX_CFG + |
| 526 | COH901318_CX_CFG_SPACING * channel); |
| 527 | |
| 528 | /* Spin-wait for it to actually go inactive */ |
| 529 | while (readl(virtbase + COH901318_CX_STAT+COH901318_CX_STAT_SPACING * |
| 530 | channel) & COH901318_CX_STAT_ACTIVE) |
| 531 | cpu_relax(); |
| 532 | |
| 533 | /* Check if we stopped an active job */ |
| 534 | if ((readl(virtbase + COH901318_CX_CTRL+COH901318_CX_CTRL_SPACING * |
| 535 | channel) & COH901318_CX_CTRL_TC_VALUE_MASK) > 0) |
| 536 | cohc->stopped = 1; |
| 537 | |
| 538 | enable_powersave(cohc); |
| 539 | |
| 540 | spin_unlock_irqrestore(&cohc->lock, flags); |
| 541 | } |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 542 | |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 543 | /* Resumes a transfer that has been stopped via 300_dma_stop(..). |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 544 | Power save is handled. |
| 545 | */ |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 546 | static void coh901318_resume(struct dma_chan *chan) |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 547 | { |
| 548 | u32 val; |
| 549 | unsigned long flags; |
| 550 | struct coh901318_chan *cohc = to_coh901318_chan(chan); |
| 551 | int channel = cohc->id; |
| 552 | |
| 553 | spin_lock_irqsave(&cohc->lock, flags); |
| 554 | |
| 555 | disable_powersave(cohc); |
| 556 | |
| 557 | if (cohc->stopped) { |
| 558 | /* Enable channel in HW */ |
| 559 | val = readl(cohc->base->virtbase + COH901318_CX_CFG + |
| 560 | COH901318_CX_CFG_SPACING * channel); |
| 561 | |
| 562 | val |= COH901318_CX_CFG_CH_ENABLE; |
| 563 | |
| 564 | writel(val, cohc->base->virtbase + COH901318_CX_CFG + |
| 565 | COH901318_CX_CFG_SPACING*channel); |
| 566 | |
| 567 | cohc->stopped = 0; |
| 568 | } |
| 569 | |
| 570 | spin_unlock_irqrestore(&cohc->lock, flags); |
| 571 | } |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 572 | |
| 573 | bool coh901318_filter_id(struct dma_chan *chan, void *chan_id) |
| 574 | { |
| 575 | unsigned int ch_nr = (unsigned int) chan_id; |
| 576 | |
| 577 | if (ch_nr == to_coh901318_chan(chan)->id) |
| 578 | return true; |
| 579 | |
| 580 | return false; |
| 581 | } |
| 582 | EXPORT_SYMBOL(coh901318_filter_id); |
| 583 | |
| 584 | /* |
| 585 | * DMA channel allocation |
| 586 | */ |
| 587 | static int coh901318_config(struct coh901318_chan *cohc, |
| 588 | struct coh901318_params *param) |
| 589 | { |
| 590 | unsigned long flags; |
| 591 | const struct coh901318_params *p; |
| 592 | int channel = cohc->id; |
| 593 | void __iomem *virtbase = cohc->base->virtbase; |
| 594 | |
| 595 | spin_lock_irqsave(&cohc->lock, flags); |
| 596 | |
| 597 | if (param) |
| 598 | p = param; |
| 599 | else |
| 600 | p = &cohc->base->platform->chan_conf[channel].param; |
| 601 | |
| 602 | /* Clear any pending BE or TC interrupt */ |
| 603 | if (channel < 32) { |
| 604 | writel(1 << channel, virtbase + COH901318_BE_INT_CLEAR1); |
| 605 | writel(1 << channel, virtbase + COH901318_TC_INT_CLEAR1); |
| 606 | } else { |
| 607 | writel(1 << (channel - 32), virtbase + |
| 608 | COH901318_BE_INT_CLEAR2); |
| 609 | writel(1 << (channel - 32), virtbase + |
| 610 | COH901318_TC_INT_CLEAR2); |
| 611 | } |
| 612 | |
| 613 | coh901318_set_conf(cohc, p->config); |
| 614 | coh901318_set_ctrl(cohc, p->ctrl_lli_last); |
| 615 | |
| 616 | spin_unlock_irqrestore(&cohc->lock, flags); |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | /* must lock when calling this function |
| 622 | * start queued jobs, if any |
| 623 | * TODO: start all queued jobs in one go |
| 624 | * |
| 625 | * Returns descriptor if queued job is started otherwise NULL. |
| 626 | * If the queue is empty NULL is returned. |
| 627 | */ |
| 628 | static struct coh901318_desc *coh901318_queue_start(struct coh901318_chan *cohc) |
| 629 | { |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 630 | struct coh901318_desc *cohd; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 631 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 632 | /* |
| 633 | * start queued jobs, if any |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 634 | * TODO: transmit all queued jobs in one go |
| 635 | */ |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 636 | cohd = coh901318_first_queued(cohc); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 637 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 638 | if (cohd != NULL) { |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 639 | /* Remove from queue */ |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 640 | coh901318_desc_remove(cohd); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 641 | /* initiate DMA job */ |
| 642 | cohc->busy = 1; |
| 643 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 644 | coh901318_desc_submit(cohc, cohd); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 645 | |
Linus Walleij | b89243d | 2011-07-01 16:47:28 +0200 | [diff] [blame] | 646 | /* Program the transaction head */ |
| 647 | coh901318_set_conf(cohc, cohd->head_config); |
| 648 | coh901318_set_ctrl(cohc, cohd->head_ctrl); |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 649 | coh901318_prep_linked_list(cohc, cohd->lli); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 650 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 651 | /* start dma job on this channel */ |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 652 | coh901318_start(cohc); |
| 653 | |
| 654 | } |
| 655 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 656 | return cohd; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 657 | } |
| 658 | |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 659 | /* |
| 660 | * This tasklet is called from the interrupt handler to |
| 661 | * handle each descriptor (DMA job) that is sent to a channel. |
| 662 | */ |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 663 | static void dma_tasklet(unsigned long data) |
| 664 | { |
| 665 | struct coh901318_chan *cohc = (struct coh901318_chan *) data; |
| 666 | struct coh901318_desc *cohd_fin; |
| 667 | unsigned long flags; |
| 668 | dma_async_tx_callback callback; |
| 669 | void *callback_param; |
| 670 | |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 671 | dev_vdbg(COHC_2_DEV(cohc), "[%s] chan_id %d" |
| 672 | " nbr_active_done %ld\n", __func__, |
| 673 | cohc->id, cohc->nbr_active_done); |
| 674 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 675 | spin_lock_irqsave(&cohc->lock, flags); |
| 676 | |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 677 | /* get first active descriptor entry from list */ |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 678 | cohd_fin = coh901318_first_active_get(cohc); |
| 679 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 680 | if (cohd_fin == NULL) |
| 681 | goto err; |
| 682 | |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 683 | /* locate callback to client */ |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 684 | callback = cohd_fin->desc.callback; |
| 685 | callback_param = cohd_fin->desc.callback_param; |
| 686 | |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 687 | /* sign this job as completed on the channel */ |
Russell King - ARM Linux | f7fbce0 | 2012-03-06 22:35:07 +0000 | [diff] [blame] | 688 | dma_cookie_complete(&cohd_fin->desc); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 689 | |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 690 | /* release the lli allocation and remove the descriptor */ |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 691 | coh901318_lli_free(&cohc->base->pool, &cohd_fin->lli); |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 692 | |
| 693 | /* return desc to free-list */ |
| 694 | coh901318_desc_remove(cohd_fin); |
| 695 | coh901318_desc_free(cohc, cohd_fin); |
| 696 | |
| 697 | spin_unlock_irqrestore(&cohc->lock, flags); |
| 698 | |
| 699 | /* Call the callback when we're done */ |
| 700 | if (callback) |
| 701 | callback(callback_param); |
| 702 | |
| 703 | spin_lock_irqsave(&cohc->lock, flags); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 704 | |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 705 | /* |
| 706 | * If another interrupt fired while the tasklet was scheduling, |
| 707 | * we don't get called twice, so we have this number of active |
| 708 | * counter that keep track of the number of IRQs expected to |
| 709 | * be handled for this channel. If there happen to be more than |
| 710 | * one IRQ to be ack:ed, we simply schedule this tasklet again. |
| 711 | */ |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 712 | cohc->nbr_active_done--; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 713 | if (cohc->nbr_active_done) { |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 714 | dev_dbg(COHC_2_DEV(cohc), "scheduling tasklet again, new IRQs " |
| 715 | "came in while we were scheduling this tasklet\n"); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 716 | if (cohc_chan_conf(cohc)->priority_high) |
| 717 | tasklet_hi_schedule(&cohc->tasklet); |
| 718 | else |
| 719 | tasklet_schedule(&cohc->tasklet); |
| 720 | } |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 721 | |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 722 | spin_unlock_irqrestore(&cohc->lock, flags); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 723 | |
| 724 | return; |
| 725 | |
| 726 | err: |
| 727 | spin_unlock_irqrestore(&cohc->lock, flags); |
| 728 | dev_err(COHC_2_DEV(cohc), "[%s] No active dma desc\n", __func__); |
| 729 | } |
| 730 | |
| 731 | |
| 732 | /* called from interrupt context */ |
| 733 | static void dma_tc_handle(struct coh901318_chan *cohc) |
| 734 | { |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 735 | /* |
| 736 | * If the channel is not allocated, then we shouldn't have |
| 737 | * any TC interrupts on it. |
| 738 | */ |
| 739 | if (!cohc->allocated) { |
| 740 | dev_err(COHC_2_DEV(cohc), "spurious interrupt from " |
| 741 | "unallocated channel\n"); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 742 | return; |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 743 | } |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 744 | |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 745 | spin_lock(&cohc->lock); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 746 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 747 | /* |
| 748 | * When we reach this point, at least one queue item |
| 749 | * should have been moved over from cohc->queue to |
| 750 | * cohc->active and run to completion, that is why we're |
| 751 | * getting a terminal count interrupt is it not? |
| 752 | * If you get this BUG() the most probable cause is that |
| 753 | * the individual nodes in the lli chain have IRQ enabled, |
| 754 | * so check your platform config for lli chain ctrl. |
| 755 | */ |
| 756 | BUG_ON(list_empty(&cohc->active)); |
| 757 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 758 | cohc->nbr_active_done++; |
| 759 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 760 | /* |
| 761 | * This attempt to take a job from cohc->queue, put it |
| 762 | * into cohc->active and start it. |
| 763 | */ |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 764 | if (coh901318_queue_start(cohc) == NULL) |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 765 | cohc->busy = 0; |
| 766 | |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 767 | spin_unlock(&cohc->lock); |
| 768 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 769 | /* |
| 770 | * This tasklet will remove items from cohc->active |
| 771 | * and thus terminates them. |
| 772 | */ |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 773 | if (cohc_chan_conf(cohc)->priority_high) |
| 774 | tasklet_hi_schedule(&cohc->tasklet); |
| 775 | else |
| 776 | tasklet_schedule(&cohc->tasklet); |
| 777 | } |
| 778 | |
| 779 | |
| 780 | static irqreturn_t dma_irq_handler(int irq, void *dev_id) |
| 781 | { |
| 782 | u32 status1; |
| 783 | u32 status2; |
| 784 | int i; |
| 785 | int ch; |
| 786 | struct coh901318_base *base = dev_id; |
| 787 | struct coh901318_chan *cohc; |
| 788 | void __iomem *virtbase = base->virtbase; |
| 789 | |
| 790 | status1 = readl(virtbase + COH901318_INT_STATUS1); |
| 791 | status2 = readl(virtbase + COH901318_INT_STATUS2); |
| 792 | |
| 793 | if (unlikely(status1 == 0 && status2 == 0)) { |
| 794 | dev_warn(base->dev, "spurious DMA IRQ from no channel!\n"); |
| 795 | return IRQ_HANDLED; |
| 796 | } |
| 797 | |
| 798 | /* TODO: consider handle IRQ in tasklet here to |
| 799 | * minimize interrupt latency */ |
| 800 | |
| 801 | /* Check the first 32 DMA channels for IRQ */ |
| 802 | while (status1) { |
| 803 | /* Find first bit set, return as a number. */ |
| 804 | i = ffs(status1) - 1; |
| 805 | ch = i; |
| 806 | |
| 807 | cohc = &base->chans[ch]; |
| 808 | spin_lock(&cohc->lock); |
| 809 | |
| 810 | /* Mask off this bit */ |
| 811 | status1 &= ~(1 << i); |
| 812 | /* Check the individual channel bits */ |
| 813 | if (test_bit(i, virtbase + COH901318_BE_INT_STATUS1)) { |
| 814 | dev_crit(COHC_2_DEV(cohc), |
| 815 | "DMA bus error on channel %d!\n", ch); |
| 816 | BUG_ON(1); |
| 817 | /* Clear BE interrupt */ |
| 818 | __set_bit(i, virtbase + COH901318_BE_INT_CLEAR1); |
| 819 | } else { |
| 820 | /* Caused by TC, really? */ |
| 821 | if (unlikely(!test_bit(i, virtbase + |
| 822 | COH901318_TC_INT_STATUS1))) { |
| 823 | dev_warn(COHC_2_DEV(cohc), |
| 824 | "ignoring interrupt not caused by terminal count on channel %d\n", ch); |
| 825 | /* Clear TC interrupt */ |
| 826 | BUG_ON(1); |
| 827 | __set_bit(i, virtbase + COH901318_TC_INT_CLEAR1); |
| 828 | } else { |
| 829 | /* Enable powersave if transfer has finished */ |
| 830 | if (!(readl(virtbase + COH901318_CX_STAT + |
| 831 | COH901318_CX_STAT_SPACING*ch) & |
| 832 | COH901318_CX_STAT_ENABLED)) { |
| 833 | enable_powersave(cohc); |
| 834 | } |
| 835 | |
| 836 | /* Must clear TC interrupt before calling |
| 837 | * dma_tc_handle |
Justin P. Mattock | bc0b44c | 2011-01-28 11:48:18 -0800 | [diff] [blame] | 838 | * in case tc_handle initiate a new dma job |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 839 | */ |
| 840 | __set_bit(i, virtbase + COH901318_TC_INT_CLEAR1); |
| 841 | |
| 842 | dma_tc_handle(cohc); |
| 843 | } |
| 844 | } |
| 845 | spin_unlock(&cohc->lock); |
| 846 | } |
| 847 | |
| 848 | /* Check the remaining 32 DMA channels for IRQ */ |
| 849 | while (status2) { |
| 850 | /* Find first bit set, return as a number. */ |
| 851 | i = ffs(status2) - 1; |
| 852 | ch = i + 32; |
| 853 | cohc = &base->chans[ch]; |
| 854 | spin_lock(&cohc->lock); |
| 855 | |
| 856 | /* Mask off this bit */ |
| 857 | status2 &= ~(1 << i); |
| 858 | /* Check the individual channel bits */ |
| 859 | if (test_bit(i, virtbase + COH901318_BE_INT_STATUS2)) { |
| 860 | dev_crit(COHC_2_DEV(cohc), |
| 861 | "DMA bus error on channel %d!\n", ch); |
| 862 | /* Clear BE interrupt */ |
| 863 | BUG_ON(1); |
| 864 | __set_bit(i, virtbase + COH901318_BE_INT_CLEAR2); |
| 865 | } else { |
| 866 | /* Caused by TC, really? */ |
| 867 | if (unlikely(!test_bit(i, virtbase + |
| 868 | COH901318_TC_INT_STATUS2))) { |
| 869 | dev_warn(COHC_2_DEV(cohc), |
| 870 | "ignoring interrupt not caused by terminal count on channel %d\n", ch); |
| 871 | /* Clear TC interrupt */ |
| 872 | __set_bit(i, virtbase + COH901318_TC_INT_CLEAR2); |
| 873 | BUG_ON(1); |
| 874 | } else { |
| 875 | /* Enable powersave if transfer has finished */ |
| 876 | if (!(readl(virtbase + COH901318_CX_STAT + |
| 877 | COH901318_CX_STAT_SPACING*ch) & |
| 878 | COH901318_CX_STAT_ENABLED)) { |
| 879 | enable_powersave(cohc); |
| 880 | } |
| 881 | /* Must clear TC interrupt before calling |
| 882 | * dma_tc_handle |
Justin P. Mattock | bc0b44c | 2011-01-28 11:48:18 -0800 | [diff] [blame] | 883 | * in case tc_handle initiate a new dma job |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 884 | */ |
| 885 | __set_bit(i, virtbase + COH901318_TC_INT_CLEAR2); |
| 886 | |
| 887 | dma_tc_handle(cohc); |
| 888 | } |
| 889 | } |
| 890 | spin_unlock(&cohc->lock); |
| 891 | } |
| 892 | |
| 893 | return IRQ_HANDLED; |
| 894 | } |
| 895 | |
| 896 | static int coh901318_alloc_chan_resources(struct dma_chan *chan) |
| 897 | { |
| 898 | struct coh901318_chan *cohc = to_coh901318_chan(chan); |
Linus Walleij | 84c8447 | 2010-03-04 14:40:30 +0100 | [diff] [blame] | 899 | unsigned long flags; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 900 | |
| 901 | dev_vdbg(COHC_2_DEV(cohc), "[%s] DMA channel %d\n", |
| 902 | __func__, cohc->id); |
| 903 | |
| 904 | if (chan->client_count > 1) |
| 905 | return -EBUSY; |
| 906 | |
Linus Walleij | 84c8447 | 2010-03-04 14:40:30 +0100 | [diff] [blame] | 907 | spin_lock_irqsave(&cohc->lock, flags); |
| 908 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 909 | coh901318_config(cohc, NULL); |
| 910 | |
| 911 | cohc->allocated = 1; |
Russell King - ARM Linux | d3ee98cdc | 2012-03-06 22:35:47 +0000 | [diff] [blame] | 912 | dma_cookie_init(chan); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 913 | |
Linus Walleij | 84c8447 | 2010-03-04 14:40:30 +0100 | [diff] [blame] | 914 | spin_unlock_irqrestore(&cohc->lock, flags); |
| 915 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 916 | return 1; |
| 917 | } |
| 918 | |
| 919 | static void |
| 920 | coh901318_free_chan_resources(struct dma_chan *chan) |
| 921 | { |
| 922 | struct coh901318_chan *cohc = to_coh901318_chan(chan); |
| 923 | int channel = cohc->id; |
| 924 | unsigned long flags; |
| 925 | |
| 926 | spin_lock_irqsave(&cohc->lock, flags); |
| 927 | |
| 928 | /* Disable HW */ |
| 929 | writel(0x00000000U, cohc->base->virtbase + COH901318_CX_CFG + |
| 930 | COH901318_CX_CFG_SPACING*channel); |
| 931 | writel(0x00000000U, cohc->base->virtbase + COH901318_CX_CTRL + |
| 932 | COH901318_CX_CTRL_SPACING*channel); |
| 933 | |
| 934 | cohc->allocated = 0; |
| 935 | |
| 936 | spin_unlock_irqrestore(&cohc->lock, flags); |
| 937 | |
Linus Walleij | 0582763 | 2010-05-17 16:30:42 -0700 | [diff] [blame] | 938 | chan->device->device_control(chan, DMA_TERMINATE_ALL, 0); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | |
| 942 | static dma_cookie_t |
| 943 | coh901318_tx_submit(struct dma_async_tx_descriptor *tx) |
| 944 | { |
| 945 | struct coh901318_desc *cohd = container_of(tx, struct coh901318_desc, |
| 946 | desc); |
| 947 | struct coh901318_chan *cohc = to_coh901318_chan(tx->chan); |
| 948 | unsigned long flags; |
Russell King - ARM Linux | 884485e | 2012-03-06 22:34:46 +0000 | [diff] [blame] | 949 | dma_cookie_t cookie; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 950 | |
| 951 | spin_lock_irqsave(&cohc->lock, flags); |
Russell King - ARM Linux | 884485e | 2012-03-06 22:34:46 +0000 | [diff] [blame] | 952 | cookie = dma_cookie_assign(tx); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 953 | |
| 954 | coh901318_desc_queue(cohc, cohd); |
| 955 | |
| 956 | spin_unlock_irqrestore(&cohc->lock, flags); |
| 957 | |
Russell King - ARM Linux | 884485e | 2012-03-06 22:34:46 +0000 | [diff] [blame] | 958 | return cookie; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static struct dma_async_tx_descriptor * |
| 962 | coh901318_prep_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, |
| 963 | size_t size, unsigned long flags) |
| 964 | { |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 965 | struct coh901318_lli *lli; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 966 | struct coh901318_desc *cohd; |
| 967 | unsigned long flg; |
| 968 | struct coh901318_chan *cohc = to_coh901318_chan(chan); |
| 969 | int lli_len; |
| 970 | u32 ctrl_last = cohc_chan_param(cohc)->ctrl_lli_last; |
Linus Walleij | b87108a | 2010-03-02 14:17:20 -0700 | [diff] [blame] | 971 | int ret; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 972 | |
| 973 | spin_lock_irqsave(&cohc->lock, flg); |
| 974 | |
| 975 | dev_vdbg(COHC_2_DEV(cohc), |
| 976 | "[%s] channel %d src 0x%x dest 0x%x size %d\n", |
| 977 | __func__, cohc->id, src, dest, size); |
| 978 | |
| 979 | if (flags & DMA_PREP_INTERRUPT) |
| 980 | /* Trigger interrupt after last lli */ |
| 981 | ctrl_last |= COH901318_CX_CTRL_TC_IRQ_ENABLE; |
| 982 | |
| 983 | lli_len = size >> MAX_DMA_PACKET_SIZE_SHIFT; |
| 984 | if ((lli_len << MAX_DMA_PACKET_SIZE_SHIFT) < size) |
| 985 | lli_len++; |
| 986 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 987 | lli = coh901318_lli_alloc(&cohc->base->pool, lli_len); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 988 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 989 | if (lli == NULL) |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 990 | goto err; |
| 991 | |
Linus Walleij | b87108a | 2010-03-02 14:17:20 -0700 | [diff] [blame] | 992 | ret = coh901318_lli_fill_memcpy( |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 993 | &cohc->base->pool, lli, src, size, dest, |
Linus Walleij | b87108a | 2010-03-02 14:17:20 -0700 | [diff] [blame] | 994 | cohc_chan_param(cohc)->ctrl_lli_chained, |
| 995 | ctrl_last); |
| 996 | if (ret) |
| 997 | goto err; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 998 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 999 | COH_DBG(coh901318_list_print(cohc, lli)); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1000 | |
Linus Walleij | b87108a | 2010-03-02 14:17:20 -0700 | [diff] [blame] | 1001 | /* Pick a descriptor to handle this transfer */ |
| 1002 | cohd = coh901318_desc_get(cohc); |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 1003 | cohd->lli = lli; |
Linus Walleij | b87108a | 2010-03-02 14:17:20 -0700 | [diff] [blame] | 1004 | cohd->flags = flags; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1005 | cohd->desc.tx_submit = coh901318_tx_submit; |
| 1006 | |
| 1007 | spin_unlock_irqrestore(&cohc->lock, flg); |
| 1008 | |
| 1009 | return &cohd->desc; |
| 1010 | err: |
| 1011 | spin_unlock_irqrestore(&cohc->lock, flg); |
| 1012 | return NULL; |
| 1013 | } |
| 1014 | |
| 1015 | static struct dma_async_tx_descriptor * |
| 1016 | coh901318_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1017 | unsigned int sg_len, enum dma_transfer_direction direction, |
Alexandre Bounine | 185ecb5 | 2012-03-08 15:35:13 -0500 | [diff] [blame] | 1018 | unsigned long flags, void *context) |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1019 | { |
| 1020 | struct coh901318_chan *cohc = to_coh901318_chan(chan); |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 1021 | struct coh901318_lli *lli; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1022 | struct coh901318_desc *cohd; |
Linus Walleij | 516fd43 | 2010-03-02 20:12:46 +0100 | [diff] [blame] | 1023 | const struct coh901318_params *params; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1024 | struct scatterlist *sg; |
| 1025 | int len = 0; |
| 1026 | int size; |
| 1027 | int i; |
| 1028 | u32 ctrl_chained = cohc_chan_param(cohc)->ctrl_lli_chained; |
| 1029 | u32 ctrl = cohc_chan_param(cohc)->ctrl_lli; |
| 1030 | u32 ctrl_last = cohc_chan_param(cohc)->ctrl_lli_last; |
Linus Walleij | 516fd43 | 2010-03-02 20:12:46 +0100 | [diff] [blame] | 1031 | u32 config; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1032 | unsigned long flg; |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 1033 | int ret; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1034 | |
| 1035 | if (!sgl) |
| 1036 | goto out; |
Lars-Peter Clausen | fdaf9c4 | 2012-04-25 20:50:52 +0200 | [diff] [blame] | 1037 | if (sg_dma_len(sgl) == 0) |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1038 | goto out; |
| 1039 | |
| 1040 | spin_lock_irqsave(&cohc->lock, flg); |
| 1041 | |
| 1042 | dev_vdbg(COHC_2_DEV(cohc), "[%s] sg_len %d dir %d\n", |
| 1043 | __func__, sg_len, direction); |
| 1044 | |
| 1045 | if (flags & DMA_PREP_INTERRUPT) |
| 1046 | /* Trigger interrupt after last lli */ |
| 1047 | ctrl_last |= COH901318_CX_CTRL_TC_IRQ_ENABLE; |
| 1048 | |
Linus Walleij | 516fd43 | 2010-03-02 20:12:46 +0100 | [diff] [blame] | 1049 | params = cohc_chan_param(cohc); |
| 1050 | config = params->config; |
Linus Walleij | 128f904 | 2010-08-04 13:37:53 +0200 | [diff] [blame] | 1051 | /* |
| 1052 | * Add runtime-specific control on top, make |
| 1053 | * sure the bits you set per peripheral channel are |
| 1054 | * cleared in the default config from the platform. |
| 1055 | */ |
| 1056 | ctrl_chained |= cohc->runtime_ctrl; |
| 1057 | ctrl_last |= cohc->runtime_ctrl; |
| 1058 | ctrl |= cohc->runtime_ctrl; |
Linus Walleij | 516fd43 | 2010-03-02 20:12:46 +0100 | [diff] [blame] | 1059 | |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1060 | if (direction == DMA_MEM_TO_DEV) { |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1061 | u32 tx_flags = COH901318_CX_CTRL_PRDD_SOURCE | |
| 1062 | COH901318_CX_CTRL_SRC_ADDR_INC_ENABLE; |
| 1063 | |
Linus Walleij | 516fd43 | 2010-03-02 20:12:46 +0100 | [diff] [blame] | 1064 | config |= COH901318_CX_CFG_RM_MEMORY_TO_PRIMARY; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1065 | ctrl_chained |= tx_flags; |
| 1066 | ctrl_last |= tx_flags; |
| 1067 | ctrl |= tx_flags; |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1068 | } else if (direction == DMA_DEV_TO_MEM) { |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1069 | u32 rx_flags = COH901318_CX_CTRL_PRDD_DEST | |
| 1070 | COH901318_CX_CTRL_DST_ADDR_INC_ENABLE; |
| 1071 | |
Linus Walleij | 516fd43 | 2010-03-02 20:12:46 +0100 | [diff] [blame] | 1072 | config |= COH901318_CX_CFG_RM_PRIMARY_TO_MEMORY; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1073 | ctrl_chained |= rx_flags; |
| 1074 | ctrl_last |= rx_flags; |
| 1075 | ctrl |= rx_flags; |
| 1076 | } else |
| 1077 | goto err_direction; |
| 1078 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1079 | /* The dma only supports transmitting packages up to |
| 1080 | * MAX_DMA_PACKET_SIZE. Calculate to total number of |
| 1081 | * dma elemts required to send the entire sg list |
| 1082 | */ |
| 1083 | for_each_sg(sgl, sg, sg_len, i) { |
| 1084 | unsigned int factor; |
| 1085 | size = sg_dma_len(sg); |
| 1086 | |
| 1087 | if (size <= MAX_DMA_PACKET_SIZE) { |
| 1088 | len++; |
| 1089 | continue; |
| 1090 | } |
| 1091 | |
| 1092 | factor = size >> MAX_DMA_PACKET_SIZE_SHIFT; |
| 1093 | if ((factor << MAX_DMA_PACKET_SIZE_SHIFT) < size) |
| 1094 | factor++; |
| 1095 | |
| 1096 | len += factor; |
| 1097 | } |
| 1098 | |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 1099 | pr_debug("Allocate %d lli:s for this transfer\n", len); |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 1100 | lli = coh901318_lli_alloc(&cohc->base->pool, len); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1101 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 1102 | if (lli == NULL) |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1103 | goto err_dma_alloc; |
| 1104 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 1105 | /* initiate allocated lli list */ |
| 1106 | ret = coh901318_lli_fill_sg(&cohc->base->pool, lli, sgl, sg_len, |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 1107 | cohc_dev_addr(cohc), |
| 1108 | ctrl_chained, |
| 1109 | ctrl, |
| 1110 | ctrl_last, |
| 1111 | direction, COH901318_CX_CTRL_TC_IRQ_ENABLE); |
| 1112 | if (ret) |
| 1113 | goto err_lli_fill; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1114 | |
Linus Walleij | 128f904 | 2010-08-04 13:37:53 +0200 | [diff] [blame] | 1115 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 1116 | COH_DBG(coh901318_list_print(cohc, lli)); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1117 | |
Linus Walleij | b87108a | 2010-03-02 14:17:20 -0700 | [diff] [blame] | 1118 | /* Pick a descriptor to handle this transfer */ |
| 1119 | cohd = coh901318_desc_get(cohc); |
Linus Walleij | b89243d | 2011-07-01 16:47:28 +0200 | [diff] [blame] | 1120 | cohd->head_config = config; |
| 1121 | /* |
| 1122 | * Set the default head ctrl for the channel to the one from the |
| 1123 | * lli, things may have changed due to odd buffer alignment |
| 1124 | * etc. |
| 1125 | */ |
| 1126 | cohd->head_ctrl = lli->control; |
Linus Walleij | b87108a | 2010-03-02 14:17:20 -0700 | [diff] [blame] | 1127 | cohd->dir = direction; |
| 1128 | cohd->flags = flags; |
| 1129 | cohd->desc.tx_submit = coh901318_tx_submit; |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 1130 | cohd->lli = lli; |
Linus Walleij | b87108a | 2010-03-02 14:17:20 -0700 | [diff] [blame] | 1131 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1132 | spin_unlock_irqrestore(&cohc->lock, flg); |
| 1133 | |
| 1134 | return &cohd->desc; |
Linus Walleij | 0b58828 | 2010-03-02 14:17:44 -0700 | [diff] [blame] | 1135 | err_lli_fill: |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1136 | err_dma_alloc: |
| 1137 | err_direction: |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1138 | spin_unlock_irqrestore(&cohc->lock, flg); |
| 1139 | out: |
| 1140 | return NULL; |
| 1141 | } |
| 1142 | |
| 1143 | static enum dma_status |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1144 | coh901318_tx_status(struct dma_chan *chan, dma_cookie_t cookie, |
| 1145 | struct dma_tx_state *txstate) |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1146 | { |
| 1147 | struct coh901318_chan *cohc = to_coh901318_chan(chan); |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 1148 | enum dma_status ret; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1149 | |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 1150 | ret = dma_cookie_status(chan, cookie, txstate); |
| 1151 | /* FIXME: should be conditional on ret != DMA_SUCCESS? */ |
| 1152 | dma_set_residue(txstate, coh901318_get_bytes_left(chan)); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1153 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1154 | if (ret == DMA_IN_PROGRESS && cohc->stopped) |
| 1155 | ret = DMA_PAUSED; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1156 | |
| 1157 | return ret; |
| 1158 | } |
| 1159 | |
| 1160 | static void |
| 1161 | coh901318_issue_pending(struct dma_chan *chan) |
| 1162 | { |
| 1163 | struct coh901318_chan *cohc = to_coh901318_chan(chan); |
| 1164 | unsigned long flags; |
| 1165 | |
| 1166 | spin_lock_irqsave(&cohc->lock, flags); |
| 1167 | |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 1168 | /* |
| 1169 | * Busy means that pending jobs are already being processed, |
| 1170 | * and then there is no point in starting the queue: the |
| 1171 | * terminal count interrupt on the channel will take the next |
| 1172 | * job on the queue and execute it anyway. |
| 1173 | */ |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1174 | if (!cohc->busy) |
| 1175 | coh901318_queue_start(cohc); |
| 1176 | |
| 1177 | spin_unlock_irqrestore(&cohc->lock, flags); |
| 1178 | } |
| 1179 | |
Linus Walleij | 128f904 | 2010-08-04 13:37:53 +0200 | [diff] [blame] | 1180 | /* |
| 1181 | * Here we wrap in the runtime dma control interface |
| 1182 | */ |
| 1183 | struct burst_table { |
| 1184 | int burst_8bit; |
| 1185 | int burst_16bit; |
| 1186 | int burst_32bit; |
| 1187 | u32 reg; |
| 1188 | }; |
| 1189 | |
| 1190 | static const struct burst_table burst_sizes[] = { |
| 1191 | { |
| 1192 | .burst_8bit = 64, |
| 1193 | .burst_16bit = 32, |
| 1194 | .burst_32bit = 16, |
| 1195 | .reg = COH901318_CX_CTRL_BURST_COUNT_64_BYTES, |
| 1196 | }, |
| 1197 | { |
| 1198 | .burst_8bit = 48, |
| 1199 | .burst_16bit = 24, |
| 1200 | .burst_32bit = 12, |
| 1201 | .reg = COH901318_CX_CTRL_BURST_COUNT_48_BYTES, |
| 1202 | }, |
| 1203 | { |
| 1204 | .burst_8bit = 32, |
| 1205 | .burst_16bit = 16, |
| 1206 | .burst_32bit = 8, |
| 1207 | .reg = COH901318_CX_CTRL_BURST_COUNT_32_BYTES, |
| 1208 | }, |
| 1209 | { |
| 1210 | .burst_8bit = 16, |
| 1211 | .burst_16bit = 8, |
| 1212 | .burst_32bit = 4, |
| 1213 | .reg = COH901318_CX_CTRL_BURST_COUNT_16_BYTES, |
| 1214 | }, |
| 1215 | { |
| 1216 | .burst_8bit = 8, |
| 1217 | .burst_16bit = 4, |
| 1218 | .burst_32bit = 2, |
| 1219 | .reg = COH901318_CX_CTRL_BURST_COUNT_8_BYTES, |
| 1220 | }, |
| 1221 | { |
| 1222 | .burst_8bit = 4, |
| 1223 | .burst_16bit = 2, |
| 1224 | .burst_32bit = 1, |
| 1225 | .reg = COH901318_CX_CTRL_BURST_COUNT_4_BYTES, |
| 1226 | }, |
| 1227 | { |
| 1228 | .burst_8bit = 2, |
| 1229 | .burst_16bit = 1, |
| 1230 | .burst_32bit = 0, |
| 1231 | .reg = COH901318_CX_CTRL_BURST_COUNT_2_BYTES, |
| 1232 | }, |
| 1233 | { |
| 1234 | .burst_8bit = 1, |
| 1235 | .burst_16bit = 0, |
| 1236 | .burst_32bit = 0, |
| 1237 | .reg = COH901318_CX_CTRL_BURST_COUNT_1_BYTE, |
| 1238 | }, |
| 1239 | }; |
| 1240 | |
| 1241 | static void coh901318_dma_set_runtimeconfig(struct dma_chan *chan, |
| 1242 | struct dma_slave_config *config) |
| 1243 | { |
| 1244 | struct coh901318_chan *cohc = to_coh901318_chan(chan); |
| 1245 | dma_addr_t addr; |
| 1246 | enum dma_slave_buswidth addr_width; |
| 1247 | u32 maxburst; |
| 1248 | u32 runtime_ctrl = 0; |
| 1249 | int i = 0; |
| 1250 | |
| 1251 | /* We only support mem to per or per to mem transfers */ |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1252 | if (config->direction == DMA_DEV_TO_MEM) { |
Linus Walleij | 128f904 | 2010-08-04 13:37:53 +0200 | [diff] [blame] | 1253 | addr = config->src_addr; |
| 1254 | addr_width = config->src_addr_width; |
| 1255 | maxburst = config->src_maxburst; |
Vinod Koul | db8196d | 2011-10-13 22:34:23 +0530 | [diff] [blame] | 1256 | } else if (config->direction == DMA_MEM_TO_DEV) { |
Linus Walleij | 128f904 | 2010-08-04 13:37:53 +0200 | [diff] [blame] | 1257 | addr = config->dst_addr; |
| 1258 | addr_width = config->dst_addr_width; |
| 1259 | maxburst = config->dst_maxburst; |
| 1260 | } else { |
| 1261 | dev_err(COHC_2_DEV(cohc), "illegal channel mode\n"); |
| 1262 | return; |
| 1263 | } |
| 1264 | |
| 1265 | dev_dbg(COHC_2_DEV(cohc), "configure channel for %d byte transfers\n", |
| 1266 | addr_width); |
| 1267 | switch (addr_width) { |
| 1268 | case DMA_SLAVE_BUSWIDTH_1_BYTE: |
| 1269 | runtime_ctrl |= |
| 1270 | COH901318_CX_CTRL_SRC_BUS_SIZE_8_BITS | |
| 1271 | COH901318_CX_CTRL_DST_BUS_SIZE_8_BITS; |
| 1272 | |
| 1273 | while (i < ARRAY_SIZE(burst_sizes)) { |
| 1274 | if (burst_sizes[i].burst_8bit <= maxburst) |
| 1275 | break; |
| 1276 | i++; |
| 1277 | } |
| 1278 | |
| 1279 | break; |
| 1280 | case DMA_SLAVE_BUSWIDTH_2_BYTES: |
| 1281 | runtime_ctrl |= |
| 1282 | COH901318_CX_CTRL_SRC_BUS_SIZE_16_BITS | |
| 1283 | COH901318_CX_CTRL_DST_BUS_SIZE_16_BITS; |
| 1284 | |
| 1285 | while (i < ARRAY_SIZE(burst_sizes)) { |
| 1286 | if (burst_sizes[i].burst_16bit <= maxburst) |
| 1287 | break; |
| 1288 | i++; |
| 1289 | } |
| 1290 | |
| 1291 | break; |
| 1292 | case DMA_SLAVE_BUSWIDTH_4_BYTES: |
| 1293 | /* Direction doesn't matter here, it's 32/32 bits */ |
| 1294 | runtime_ctrl |= |
| 1295 | COH901318_CX_CTRL_SRC_BUS_SIZE_32_BITS | |
| 1296 | COH901318_CX_CTRL_DST_BUS_SIZE_32_BITS; |
| 1297 | |
| 1298 | while (i < ARRAY_SIZE(burst_sizes)) { |
| 1299 | if (burst_sizes[i].burst_32bit <= maxburst) |
| 1300 | break; |
| 1301 | i++; |
| 1302 | } |
| 1303 | |
| 1304 | break; |
| 1305 | default: |
| 1306 | dev_err(COHC_2_DEV(cohc), |
| 1307 | "bad runtimeconfig: alien address width\n"); |
| 1308 | return; |
| 1309 | } |
| 1310 | |
| 1311 | runtime_ctrl |= burst_sizes[i].reg; |
| 1312 | dev_dbg(COHC_2_DEV(cohc), |
| 1313 | "selected burst size %d bytes for address width %d bytes, maxburst %d\n", |
| 1314 | burst_sizes[i].burst_8bit, addr_width, maxburst); |
| 1315 | |
| 1316 | cohc->runtime_addr = addr; |
| 1317 | cohc->runtime_ctrl = runtime_ctrl; |
| 1318 | } |
| 1319 | |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 1320 | static int |
Linus Walleij | 0582763 | 2010-05-17 16:30:42 -0700 | [diff] [blame] | 1321 | coh901318_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, |
| 1322 | unsigned long arg) |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1323 | { |
| 1324 | unsigned long flags; |
| 1325 | struct coh901318_chan *cohc = to_coh901318_chan(chan); |
| 1326 | struct coh901318_desc *cohd; |
| 1327 | void __iomem *virtbase = cohc->base->virtbase; |
| 1328 | |
Linus Walleij | 128f904 | 2010-08-04 13:37:53 +0200 | [diff] [blame] | 1329 | if (cmd == DMA_SLAVE_CONFIG) { |
| 1330 | struct dma_slave_config *config = |
| 1331 | (struct dma_slave_config *) arg; |
| 1332 | |
| 1333 | coh901318_dma_set_runtimeconfig(chan, config); |
| 1334 | return 0; |
| 1335 | } |
| 1336 | |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 1337 | if (cmd == DMA_PAUSE) { |
| 1338 | coh901318_pause(chan); |
| 1339 | return 0; |
| 1340 | } |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1341 | |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 1342 | if (cmd == DMA_RESUME) { |
| 1343 | coh901318_resume(chan); |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
| 1347 | if (cmd != DMA_TERMINATE_ALL) |
| 1348 | return -ENXIO; |
| 1349 | |
| 1350 | /* The remainder of this function terminates the transfer */ |
| 1351 | coh901318_pause(chan); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1352 | spin_lock_irqsave(&cohc->lock, flags); |
| 1353 | |
| 1354 | /* Clear any pending BE or TC interrupt */ |
| 1355 | if (cohc->id < 32) { |
| 1356 | writel(1 << cohc->id, virtbase + COH901318_BE_INT_CLEAR1); |
| 1357 | writel(1 << cohc->id, virtbase + COH901318_TC_INT_CLEAR1); |
| 1358 | } else { |
| 1359 | writel(1 << (cohc->id - 32), virtbase + |
| 1360 | COH901318_BE_INT_CLEAR2); |
| 1361 | writel(1 << (cohc->id - 32), virtbase + |
| 1362 | COH901318_TC_INT_CLEAR2); |
| 1363 | } |
| 1364 | |
| 1365 | enable_powersave(cohc); |
| 1366 | |
| 1367 | while ((cohd = coh901318_first_active_get(cohc))) { |
| 1368 | /* release the lli allocation*/ |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 1369 | coh901318_lli_free(&cohc->base->pool, &cohd->lli); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1370 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1371 | /* return desc to free-list */ |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 1372 | coh901318_desc_remove(cohd); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1373 | coh901318_desc_free(cohc, cohd); |
| 1374 | } |
| 1375 | |
| 1376 | while ((cohd = coh901318_first_queued(cohc))) { |
| 1377 | /* release the lli allocation*/ |
Linus Walleij | cecd87d | 2010-03-04 14:31:47 +0100 | [diff] [blame] | 1378 | coh901318_lli_free(&cohc->base->pool, &cohd->lli); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1379 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1380 | /* return desc to free-list */ |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 1381 | coh901318_desc_remove(cohd); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1382 | coh901318_desc_free(cohc, cohd); |
| 1383 | } |
| 1384 | |
| 1385 | |
| 1386 | cohc->nbr_active_done = 0; |
| 1387 | cohc->busy = 0; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1388 | |
| 1389 | spin_unlock_irqrestore(&cohc->lock, flags); |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 1390 | |
| 1391 | return 0; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1392 | } |
Linus Walleij | 128f904 | 2010-08-04 13:37:53 +0200 | [diff] [blame] | 1393 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1394 | void coh901318_base_init(struct dma_device *dma, const int *pick_chans, |
| 1395 | struct coh901318_base *base) |
| 1396 | { |
| 1397 | int chans_i; |
| 1398 | int i = 0; |
| 1399 | struct coh901318_chan *cohc; |
| 1400 | |
| 1401 | INIT_LIST_HEAD(&dma->channels); |
| 1402 | |
| 1403 | for (chans_i = 0; pick_chans[chans_i] != -1; chans_i += 2) { |
| 1404 | for (i = pick_chans[chans_i]; i <= pick_chans[chans_i+1]; i++) { |
| 1405 | cohc = &base->chans[i]; |
| 1406 | |
| 1407 | cohc->base = base; |
| 1408 | cohc->chan.device = dma; |
| 1409 | cohc->id = i; |
| 1410 | |
| 1411 | /* TODO: do we really need this lock if only one |
| 1412 | * client is connected to each channel? |
| 1413 | */ |
| 1414 | |
| 1415 | spin_lock_init(&cohc->lock); |
| 1416 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1417 | cohc->nbr_active_done = 0; |
| 1418 | cohc->busy = 0; |
| 1419 | INIT_LIST_HEAD(&cohc->free); |
| 1420 | INIT_LIST_HEAD(&cohc->active); |
| 1421 | INIT_LIST_HEAD(&cohc->queue); |
| 1422 | |
| 1423 | tasklet_init(&cohc->tasklet, dma_tasklet, |
| 1424 | (unsigned long) cohc); |
| 1425 | |
| 1426 | list_add_tail(&cohc->chan.device_node, |
| 1427 | &dma->channels); |
| 1428 | } |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | static int __init coh901318_probe(struct platform_device *pdev) |
| 1433 | { |
| 1434 | int err = 0; |
| 1435 | struct coh901318_platform *pdata; |
| 1436 | struct coh901318_base *base; |
| 1437 | int irq; |
| 1438 | struct resource *io; |
| 1439 | |
| 1440 | io = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1441 | if (!io) |
Linus Walleij | f7ceb36 | 2012-06-12 20:19:24 +0200 | [diff] [blame] | 1442 | return -ENODEV; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1443 | |
| 1444 | /* Map DMA controller registers to virtual memory */ |
Linus Walleij | f7ceb36 | 2012-06-12 20:19:24 +0200 | [diff] [blame] | 1445 | if (devm_request_mem_region(&pdev->dev, |
| 1446 | io->start, |
| 1447 | resource_size(io), |
| 1448 | pdev->dev.driver->name) == NULL) |
| 1449 | return -ENOMEM; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1450 | |
| 1451 | pdata = pdev->dev.platform_data; |
| 1452 | if (!pdata) |
Linus Walleij | f7ceb36 | 2012-06-12 20:19:24 +0200 | [diff] [blame] | 1453 | return -ENODEV; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1454 | |
Linus Walleij | f7ceb36 | 2012-06-12 20:19:24 +0200 | [diff] [blame] | 1455 | base = devm_kzalloc(&pdev->dev, |
| 1456 | ALIGN(sizeof(struct coh901318_base), 4) + |
| 1457 | pdata->max_channels * |
| 1458 | sizeof(struct coh901318_chan), |
| 1459 | GFP_KERNEL); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1460 | if (!base) |
Linus Walleij | f7ceb36 | 2012-06-12 20:19:24 +0200 | [diff] [blame] | 1461 | return -ENOMEM; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1462 | |
| 1463 | base->chans = ((void *)base) + ALIGN(sizeof(struct coh901318_base), 4); |
| 1464 | |
Linus Walleij | f7ceb36 | 2012-06-12 20:19:24 +0200 | [diff] [blame] | 1465 | base->virtbase = devm_ioremap(&pdev->dev, io->start, resource_size(io)); |
| 1466 | if (!base->virtbase) |
| 1467 | return -ENOMEM; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1468 | |
| 1469 | base->dev = &pdev->dev; |
| 1470 | base->platform = pdata; |
| 1471 | spin_lock_init(&base->pm.lock); |
| 1472 | base->pm.started_channels = 0; |
| 1473 | |
| 1474 | COH901318_DEBUGFS_ASSIGN(debugfs_dma_base, base); |
| 1475 | |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1476 | irq = platform_get_irq(pdev, 0); |
| 1477 | if (irq < 0) |
Linus Walleij | f7ceb36 | 2012-06-12 20:19:24 +0200 | [diff] [blame] | 1478 | return irq; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1479 | |
Linus Walleij | f7ceb36 | 2012-06-12 20:19:24 +0200 | [diff] [blame] | 1480 | err = devm_request_irq(&pdev->dev, irq, dma_irq_handler, IRQF_DISABLED, |
| 1481 | "coh901318", base); |
| 1482 | if (err) |
| 1483 | return err; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1484 | |
| 1485 | err = coh901318_pool_create(&base->pool, &pdev->dev, |
| 1486 | sizeof(struct coh901318_lli), |
| 1487 | 32); |
| 1488 | if (err) |
Linus Walleij | f7ceb36 | 2012-06-12 20:19:24 +0200 | [diff] [blame] | 1489 | return err; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1490 | |
| 1491 | /* init channels for device transfers */ |
| 1492 | coh901318_base_init(&base->dma_slave, base->platform->chans_slave, |
| 1493 | base); |
| 1494 | |
| 1495 | dma_cap_zero(base->dma_slave.cap_mask); |
| 1496 | dma_cap_set(DMA_SLAVE, base->dma_slave.cap_mask); |
| 1497 | |
| 1498 | base->dma_slave.device_alloc_chan_resources = coh901318_alloc_chan_resources; |
| 1499 | base->dma_slave.device_free_chan_resources = coh901318_free_chan_resources; |
| 1500 | base->dma_slave.device_prep_slave_sg = coh901318_prep_slave_sg; |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1501 | base->dma_slave.device_tx_status = coh901318_tx_status; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1502 | base->dma_slave.device_issue_pending = coh901318_issue_pending; |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 1503 | base->dma_slave.device_control = coh901318_control; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1504 | base->dma_slave.dev = &pdev->dev; |
| 1505 | |
| 1506 | err = dma_async_device_register(&base->dma_slave); |
| 1507 | |
| 1508 | if (err) |
| 1509 | goto err_register_slave; |
| 1510 | |
| 1511 | /* init channels for memcpy */ |
| 1512 | coh901318_base_init(&base->dma_memcpy, base->platform->chans_memcpy, |
| 1513 | base); |
| 1514 | |
| 1515 | dma_cap_zero(base->dma_memcpy.cap_mask); |
| 1516 | dma_cap_set(DMA_MEMCPY, base->dma_memcpy.cap_mask); |
| 1517 | |
| 1518 | base->dma_memcpy.device_alloc_chan_resources = coh901318_alloc_chan_resources; |
| 1519 | base->dma_memcpy.device_free_chan_resources = coh901318_free_chan_resources; |
| 1520 | base->dma_memcpy.device_prep_dma_memcpy = coh901318_prep_memcpy; |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1521 | base->dma_memcpy.device_tx_status = coh901318_tx_status; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1522 | base->dma_memcpy.device_issue_pending = coh901318_issue_pending; |
Linus Walleij | c3635c7 | 2010-03-26 16:44:01 -0700 | [diff] [blame] | 1523 | base->dma_memcpy.device_control = coh901318_control; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1524 | base->dma_memcpy.dev = &pdev->dev; |
Linus Walleij | 516fd43 | 2010-03-02 20:12:46 +0100 | [diff] [blame] | 1525 | /* |
| 1526 | * This controller can only access address at even 32bit boundaries, |
| 1527 | * i.e. 2^2 |
| 1528 | */ |
| 1529 | base->dma_memcpy.copy_align = 2; |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1530 | err = dma_async_device_register(&base->dma_memcpy); |
| 1531 | |
| 1532 | if (err) |
| 1533 | goto err_register_memcpy; |
| 1534 | |
Linus Walleij | f7ceb36 | 2012-06-12 20:19:24 +0200 | [diff] [blame] | 1535 | platform_set_drvdata(pdev, base); |
Linus Walleij | 848ad12 | 2010-03-02 14:17:15 -0700 | [diff] [blame] | 1536 | dev_info(&pdev->dev, "Initialized COH901318 DMA on virtual base 0x%08x\n", |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1537 | (u32) base->virtbase); |
| 1538 | |
| 1539 | return err; |
| 1540 | |
| 1541 | err_register_memcpy: |
| 1542 | dma_async_device_unregister(&base->dma_slave); |
| 1543 | err_register_slave: |
| 1544 | coh901318_pool_destroy(&base->pool); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1545 | return err; |
| 1546 | } |
| 1547 | |
| 1548 | static int __exit coh901318_remove(struct platform_device *pdev) |
| 1549 | { |
| 1550 | struct coh901318_base *base = platform_get_drvdata(pdev); |
| 1551 | |
| 1552 | dma_async_device_unregister(&base->dma_memcpy); |
| 1553 | dma_async_device_unregister(&base->dma_slave); |
| 1554 | coh901318_pool_destroy(&base->pool); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1555 | return 0; |
| 1556 | } |
| 1557 | |
| 1558 | |
| 1559 | static struct platform_driver coh901318_driver = { |
| 1560 | .remove = __exit_p(coh901318_remove), |
| 1561 | .driver = { |
| 1562 | .name = "coh901318", |
| 1563 | }, |
| 1564 | }; |
| 1565 | |
| 1566 | int __init coh901318_init(void) |
| 1567 | { |
| 1568 | return platform_driver_probe(&coh901318_driver, coh901318_probe); |
| 1569 | } |
Linus Walleij | a0eb221 | 2011-05-18 14:18:57 +0200 | [diff] [blame] | 1570 | subsys_initcall(coh901318_init); |
Linus Walleij | 61f135b | 2009-11-19 19:49:17 +0100 | [diff] [blame] | 1571 | |
| 1572 | void __exit coh901318_exit(void) |
| 1573 | { |
| 1574 | platform_driver_unregister(&coh901318_driver); |
| 1575 | } |
| 1576 | module_exit(coh901318_exit); |
| 1577 | |
| 1578 | MODULE_LICENSE("GPL"); |
| 1579 | MODULE_AUTHOR("Per Friden"); |