Blame view
drivers/dma/at_hdmac.c
46 KB
dc78baa2b dmaengine: at_hdm... |
1 2 3 4 5 6 7 8 9 10 11 |
/* * Driver for the Atmel AHB DMA Controller (aka HDMA or DMAC on AT91 systems) * * Copyright (C) 2008 Atmel Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * |
9102d8715 dmaengine: at_hdm... |
12 13 14 |
* This supports the Atmel AHB DMA Controller found in several Atmel SoCs. * The only Atmel DMA Controller that is not covered by this driver is the one * found on AT91SAM9263. |
dc78baa2b dmaengine: at_hdm... |
15 |
*/ |
62971b298 dmaengine: at_hdm... |
16 |
#include <dt-bindings/dma/at91.h> |
dc78baa2b dmaengine: at_hdm... |
17 18 19 20 21 22 23 |
#include <linux/clk.h> #include <linux/dmaengine.h> #include <linux/dma-mapping.h> #include <linux/dmapool.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/platform_device.h> |
5a0e3ad6a include cleanup: ... |
24 |
#include <linux/slab.h> |
c51159539 dmaengine: at_hdm... |
25 26 |
#include <linux/of.h> #include <linux/of_device.h> |
bbe89c8e3 at_hdmac: move to... |
27 |
#include <linux/of_dma.h> |
dc78baa2b dmaengine: at_hdm... |
28 29 |
#include "at_hdmac_regs.h" |
d2ebfb335 dmaengine: add pr... |
30 |
#include "dmaengine.h" |
dc78baa2b dmaengine: at_hdm... |
31 32 33 34 35 36 37 38 39 40 41 |
/* * Glossary * -------- * * at_hdmac : Name of the ATmel AHB DMA Controller * at_dma_ / atdma : ATmel DMA controller entity related * atc_ / atchan : ATmel DMA Channel entity related */ #define ATC_DEFAULT_CFG (ATC_FIFOCFG_HALFFIFO) |
ae14d4b5e dmaengine: at_hdm... |
42 43 |
#define ATC_DEFAULT_CTRLB (ATC_SIF(AT_DMA_MEM_IF) \ |ATC_DIF(AT_DMA_MEM_IF)) |
dc78baa2b dmaengine: at_hdm... |
44 45 46 47 48 49 50 51 52 53 54 55 56 |
/* * Initial number of descriptors to allocate for each channel. This could * be increased during dma usage. */ static unsigned int init_nr_desc_per_channel = 64; module_param(init_nr_desc_per_channel, uint, 0644); MODULE_PARM_DESC(init_nr_desc_per_channel, "initial descriptors per channel (default: 64)"); /* prototypes */ static dma_cookie_t atc_tx_submit(struct dma_async_tx_descriptor *tx); |
d48de6f1a DMA: AT91: Get re... |
57 |
static void atc_issue_pending(struct dma_chan *chan); |
dc78baa2b dmaengine: at_hdm... |
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
/*----------------------------------------------------------------------*/ static struct at_desc *atc_first_active(struct at_dma_chan *atchan) { return list_first_entry(&atchan->active_list, struct at_desc, desc_node); } static struct at_desc *atc_first_queued(struct at_dma_chan *atchan) { return list_first_entry(&atchan->queue, struct at_desc, desc_node); } /** |
421f91d21 fix typos concern... |
75 |
* atc_alloc_descriptor - allocate and return an initialized descriptor |
dc78baa2b dmaengine: at_hdm... |
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
* @chan: the channel to allocate descriptors for * @gfp_flags: GFP allocation flags * * Note: The ack-bit is positioned in the descriptor flag at creation time * to make initial allocation more convenient. This bit will be cleared * and control will be given to client at usage time (during * preparation functions). */ static struct at_desc *atc_alloc_descriptor(struct dma_chan *chan, gfp_t gfp_flags) { struct at_desc *desc = NULL; struct at_dma *atdma = to_at_dma(chan->device); dma_addr_t phys; desc = dma_pool_alloc(atdma->dma_desc_pool, gfp_flags, &phys); if (desc) { memset(desc, 0, sizeof(struct at_desc)); |
285a3c716 at_hdmac: impleme... |
94 |
INIT_LIST_HEAD(&desc->tx_list); |
dc78baa2b dmaengine: at_hdm... |
95 96 97 98 99 100 101 102 103 104 105 |
dma_async_tx_descriptor_init(&desc->txd, chan); /* txd.flags will be overwritten in prep functions */ desc->txd.flags = DMA_CTRL_ACK; desc->txd.tx_submit = atc_tx_submit; desc->txd.phys = phys; } return desc; } /** |
af901ca18 tree-wide: fix as... |
106 |
* atc_desc_get - get an unused descriptor from free_list |
dc78baa2b dmaengine: at_hdm... |
107 108 109 110 111 112 |
* @atchan: channel we want a new descriptor for */ static struct at_desc *atc_desc_get(struct at_dma_chan *atchan) { struct at_desc *desc, *_desc; struct at_desc *ret = NULL; |
d8cb04b07 dmaengine: at_hdm... |
113 |
unsigned long flags; |
dc78baa2b dmaengine: at_hdm... |
114 115 |
unsigned int i = 0; LIST_HEAD(tmp_list); |
d8cb04b07 dmaengine: at_hdm... |
116 |
spin_lock_irqsave(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
117 118 119 120 121 122 123 124 125 126 127 |
list_for_each_entry_safe(desc, _desc, &atchan->free_list, desc_node) { i++; if (async_tx_test_ack(&desc->txd)) { list_del(&desc->desc_node); ret = desc; break; } dev_dbg(chan2dev(&atchan->chan_common), "desc %p not ACKed ", desc); } |
d8cb04b07 dmaengine: at_hdm... |
128 |
spin_unlock_irqrestore(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
129 130 131 132 133 134 135 136 |
dev_vdbg(chan2dev(&atchan->chan_common), "scanned %u descriptors on freelist ", i); /* no more descriptor available in initial pool: create one more */ if (!ret) { ret = atc_alloc_descriptor(&atchan->chan_common, GFP_ATOMIC); if (ret) { |
d8cb04b07 dmaengine: at_hdm... |
137 |
spin_lock_irqsave(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
138 |
atchan->descs_allocated++; |
d8cb04b07 dmaengine: at_hdm... |
139 |
spin_unlock_irqrestore(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
} else { dev_err(chan2dev(&atchan->chan_common), "not enough descriptors available "); } } return ret; } /** * atc_desc_put - move a descriptor, including any children, to the free list * @atchan: channel we work on * @desc: descriptor, at the head of a chain, to move to free list */ static void atc_desc_put(struct at_dma_chan *atchan, struct at_desc *desc) { if (desc) { struct at_desc *child; |
d8cb04b07 dmaengine: at_hdm... |
159 |
unsigned long flags; |
dc78baa2b dmaengine: at_hdm... |
160 |
|
d8cb04b07 dmaengine: at_hdm... |
161 |
spin_lock_irqsave(&atchan->lock, flags); |
285a3c716 at_hdmac: impleme... |
162 |
list_for_each_entry(child, &desc->tx_list, desc_node) |
dc78baa2b dmaengine: at_hdm... |
163 164 165 166 |
dev_vdbg(chan2dev(&atchan->chan_common), "moving child desc %p to freelist ", child); |
285a3c716 at_hdmac: impleme... |
167 |
list_splice_init(&desc->tx_list, &atchan->free_list); |
dc78baa2b dmaengine: at_hdm... |
168 169 170 171 |
dev_vdbg(chan2dev(&atchan->chan_common), "moving desc %p to freelist ", desc); list_add(&desc->desc_node, &atchan->free_list); |
d8cb04b07 dmaengine: at_hdm... |
172 |
spin_unlock_irqrestore(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
173 174 175 176 |
} } /** |
d73111c6d dma: fix comments |
177 178 179 |
* atc_desc_chain - build chain adding a descriptor * @first: address of first descriptor of the chain * @prev: address of previous descriptor of the chain |
53830cc75 dmaengine: at_hdm... |
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
* @desc: descriptor to queue * * Called from prep_* functions */ static void atc_desc_chain(struct at_desc **first, struct at_desc **prev, struct at_desc *desc) { if (!(*first)) { *first = desc; } else { /* inform the HW lli about chaining */ (*prev)->lli.dscr = desc->txd.phys; /* insert the link descriptor to the LD ring */ list_add_tail(&desc->desc_node, &(*first)->tx_list); } *prev = desc; } /** |
dc78baa2b dmaengine: at_hdm... |
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
* atc_dostart - starts the DMA engine for real * @atchan: the channel we want to start * @first: first descriptor in the list we want to begin with * * Called with atchan->lock held and bh disabled */ static void atc_dostart(struct at_dma_chan *atchan, struct at_desc *first) { struct at_dma *atdma = to_at_dma(atchan->chan_common.device); /* ASSERT: channel is idle */ if (atc_chan_is_enabled(atchan)) { dev_err(chan2dev(&atchan->chan_common), "BUG: Attempted to start non-idle channel "); dev_err(chan2dev(&atchan->chan_common), " channel: s0x%x d0x%x ctrl0x%x:0x%x l0x%x ", channel_readl(atchan, SADDR), channel_readl(atchan, DADDR), channel_readl(atchan, CTRLA), channel_readl(atchan, CTRLB), channel_readl(atchan, DSCR)); /* The tasklet will hopefully advance the queue... */ return; } vdbg_dump_regs(atchan); |
dc78baa2b dmaengine: at_hdm... |
229 230 231 232 233 234 235 236 237 |
channel_writel(atchan, SADDR, 0); channel_writel(atchan, DADDR, 0); channel_writel(atchan, CTRLA, 0); channel_writel(atchan, CTRLB, 0); channel_writel(atchan, DSCR, first->txd.phys); dma_writel(atdma, CHER, atchan->mask); vdbg_dump_regs(atchan); } |
d48de6f1a DMA: AT91: Get re... |
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
/* * atc_get_current_descriptors - * locate the descriptor which equal to physical address in DSCR * @atchan: the channel we want to start * @dscr_addr: physical descriptor address in DSCR */ static struct at_desc *atc_get_current_descriptors(struct at_dma_chan *atchan, u32 dscr_addr) { struct at_desc *desc, *_desc, *child, *desc_cur = NULL; list_for_each_entry_safe(desc, _desc, &atchan->active_list, desc_node) { if (desc->lli.dscr == dscr_addr) { desc_cur = desc; break; } list_for_each_entry(child, &desc->tx_list, desc_node) { if (child->lli.dscr == dscr_addr) { desc_cur = child; break; } } } return desc_cur; } /* * atc_get_bytes_left - * Get the number of bytes residue in dma buffer, * @chan: the channel we want to start */ static int atc_get_bytes_left(struct dma_chan *chan) { struct at_dma_chan *atchan = to_at_dma_chan(chan); struct at_dma *atdma = to_at_dma(chan->device); int chan_id = atchan->chan_common.chan_id; struct at_desc *desc_first = atc_first_active(atchan); struct at_desc *desc_cur; int ret = 0, count = 0; /* * Initialize necessary values in the first time. * remain_desc record remain desc length. */ if (atchan->remain_desc == 0) /* First descriptor embedds the transaction length */ atchan->remain_desc = desc_first->len; /* * This happens when current descriptor transfer complete. * The residual buffer size should reduce current descriptor length. */ if (unlikely(test_bit(ATC_IS_BTC, &atchan->status))) { clear_bit(ATC_IS_BTC, &atchan->status); desc_cur = atc_get_current_descriptors(atchan, channel_readl(atchan, DSCR)); if (!desc_cur) { ret = -EINVAL; goto out; } atchan->remain_desc -= (desc_cur->lli.ctrla & ATC_BTSIZE_MAX) << (desc_first->tx_width); if (atchan->remain_desc < 0) { ret = -EINVAL; goto out; |
c3dbc60c9 dmaengine/trivial... |
305 |
} else { |
d48de6f1a DMA: AT91: Get re... |
306 |
ret = atchan->remain_desc; |
c3dbc60c9 dmaengine/trivial... |
307 |
} |
d48de6f1a DMA: AT91: Get re... |
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
} else { /* * Get residual bytes when current * descriptor transfer in progress. */ count = (channel_readl(atchan, CTRLA) & ATC_BTSIZE_MAX) << (desc_first->tx_width); ret = atchan->remain_desc - count; } /* * Check fifo empty. */ if (!(dma_readl(atdma, CHSR) & AT_DMA_EMPT(chan_id))) atc_issue_pending(chan); out: return ret; } |
dc78baa2b dmaengine: at_hdm... |
326 327 328 329 330 331 332 333 334 |
/** * atc_chain_complete - finish work for one transaction chain * @atchan: channel we work on * @desc: descriptor at the head of the chain we want do complete * * Called with atchan->lock held and bh disabled */ static void atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc) { |
dc78baa2b dmaengine: at_hdm... |
335 336 337 338 339 |
struct dma_async_tx_descriptor *txd = &desc->txd; dev_vdbg(chan2dev(&atchan->chan_common), "descriptor %u complete ", txd->cookie); |
d41160524 dmaengine: fix cy... |
340 341 342 |
/* mark the descriptor as complete for non cyclic cases only */ if (!atc_chan_is_cyclic(atchan)) dma_cookie_complete(txd); |
dc78baa2b dmaengine: at_hdm... |
343 344 |
/* move children to free_list */ |
285a3c716 at_hdmac: impleme... |
345 |
list_splice_init(&desc->tx_list, &atchan->free_list); |
dc78baa2b dmaengine: at_hdm... |
346 347 |
/* move myself to free_list */ list_move(&desc->desc_node, &atchan->free_list); |
d38a8c622 dmaengine: prepar... |
348 |
dma_descriptor_unmap(txd); |
53830cc75 dmaengine: at_hdm... |
349 350 |
/* for cyclic transfers, * no need to replay callback function while stopping */ |
3c477482b dmaengine: at_hdm... |
351 |
if (!atc_chan_is_cyclic(atchan)) { |
53830cc75 dmaengine: at_hdm... |
352 353 354 355 356 357 358 359 360 361 |
dma_async_tx_callback callback = txd->callback; void *param = txd->callback_param; /* * The API requires that no submissions are done from a * callback, so we don't need to drop the lock here */ if (callback) callback(param); } |
dc78baa2b dmaengine: at_hdm... |
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
dma_run_dependencies(txd); } /** * atc_complete_all - finish work for all transactions * @atchan: channel to complete transactions for * * Eventually submit queued descriptors if any * * Assume channel is idle while calling this function * Called with atchan->lock held and bh disabled */ static void atc_complete_all(struct at_dma_chan *atchan) { struct at_desc *desc, *_desc; LIST_HEAD(list); dev_vdbg(chan2dev(&atchan->chan_common), "complete all "); |
dc78baa2b dmaengine: at_hdm... |
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
/* * Submit queued descriptors ASAP, i.e. before we go through * the completed ones. */ if (!list_empty(&atchan->queue)) atc_dostart(atchan, atc_first_queued(atchan)); /* empty active_list now it is completed */ list_splice_init(&atchan->active_list, &list); /* empty queue list by moving descriptors (if any) to active_list */ list_splice_init(&atchan->queue, &atchan->active_list); list_for_each_entry_safe(desc, _desc, &list, desc_node) atc_chain_complete(atchan, desc); } /** |
dc78baa2b dmaengine: at_hdm... |
398 399 400 401 402 403 404 405 406 |
* atc_advance_work - at the end of a transaction, move forward * @atchan: channel where the transaction ended * * Called with atchan->lock held and bh disabled */ static void atc_advance_work(struct at_dma_chan *atchan) { dev_vdbg(chan2dev(&atchan->chan_common), "advance_work "); |
d202f0515 dmaengine: at_hdm... |
407 408 |
if (atc_chan_is_enabled(atchan)) return; |
dc78baa2b dmaengine: at_hdm... |
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
if (list_empty(&atchan->active_list) || list_is_singular(&atchan->active_list)) { atc_complete_all(atchan); } else { atc_chain_complete(atchan, atc_first_active(atchan)); /* advance work */ atc_dostart(atchan, atc_first_active(atchan)); } } /** * atc_handle_error - handle errors reported by DMA controller * @atchan: channel where error occurs * * Called with atchan->lock held and bh disabled */ static void atc_handle_error(struct at_dma_chan *atchan) { struct at_desc *bad_desc; struct at_desc *child; /* * The descriptor currently at the head of the active list is * broked. Since we don't have any way to report errors, we'll * just have to scream loudly and try to carry on. */ bad_desc = atc_first_active(atchan); list_del_init(&bad_desc->desc_node); /* As we are stopped, take advantage to push queued descriptors * in active_list */ list_splice_init(&atchan->queue, atchan->active_list.prev); /* Try to restart the controller */ if (!list_empty(&atchan->active_list)) atc_dostart(atchan, atc_first_active(atchan)); /* * KERN_CRITICAL may seem harsh, but since this only happens * when someone submits a bad physical address in a * descriptor, we should consider ourselves lucky that the * controller flagged an error instead of scribbling over * random memory locations. */ dev_crit(chan2dev(&atchan->chan_common), "Bad descriptor submitted for DMA! "); dev_crit(chan2dev(&atchan->chan_common), " cookie: %d ", bad_desc->txd.cookie); atc_dump_lli(atchan, &bad_desc->lli); |
285a3c716 at_hdmac: impleme... |
461 |
list_for_each_entry(child, &bad_desc->tx_list, desc_node) |
dc78baa2b dmaengine: at_hdm... |
462 463 464 465 466 |
atc_dump_lli(atchan, &child->lli); /* Pretend the descriptor completed successfully */ atc_chain_complete(atchan, bad_desc); } |
53830cc75 dmaengine: at_hdm... |
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
/** * atc_handle_cyclic - at the end of a period, run callback function * @atchan: channel used for cyclic operations * * Called with atchan->lock held and bh disabled */ static void atc_handle_cyclic(struct at_dma_chan *atchan) { struct at_desc *first = atc_first_active(atchan); struct dma_async_tx_descriptor *txd = &first->txd; dma_async_tx_callback callback = txd->callback; void *param = txd->callback_param; dev_vdbg(chan2dev(&atchan->chan_common), "new cyclic period llp 0x%08x ", channel_readl(atchan, DSCR)); if (callback) callback(param); } |
dc78baa2b dmaengine: at_hdm... |
488 489 490 491 492 493 |
/*-- IRQ & Tasklet ---------------------------------------------------*/ static void atc_tasklet(unsigned long data) { struct at_dma_chan *atchan = (struct at_dma_chan *)data; |
d8cb04b07 dmaengine: at_hdm... |
494 |
unsigned long flags; |
dc78baa2b dmaengine: at_hdm... |
495 |
|
d8cb04b07 dmaengine: at_hdm... |
496 |
spin_lock_irqsave(&atchan->lock, flags); |
53830cc75 dmaengine: at_hdm... |
497 |
if (test_and_clear_bit(ATC_IS_ERROR, &atchan->status)) |
dc78baa2b dmaengine: at_hdm... |
498 |
atc_handle_error(atchan); |
3c477482b dmaengine: at_hdm... |
499 |
else if (atc_chan_is_cyclic(atchan)) |
53830cc75 dmaengine: at_hdm... |
500 |
atc_handle_cyclic(atchan); |
dc78baa2b dmaengine: at_hdm... |
501 502 |
else atc_advance_work(atchan); |
d8cb04b07 dmaengine: at_hdm... |
503 |
spin_unlock_irqrestore(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
} static irqreturn_t at_dma_interrupt(int irq, void *dev_id) { struct at_dma *atdma = (struct at_dma *)dev_id; struct at_dma_chan *atchan; int i; u32 status, pending, imr; int ret = IRQ_NONE; do { imr = dma_readl(atdma, EBCIMR); status = dma_readl(atdma, EBCISR); pending = status & imr; if (!pending) break; dev_vdbg(atdma->dma_common.dev, "interrupt: status = 0x%08x, 0x%08x, 0x%08x ", status, imr, pending); for (i = 0; i < atdma->dma_common.chancnt; i++) { atchan = &atdma->chan[i]; |
9b3aa589e dmaengine: at_hdm... |
529 |
if (pending & (AT_DMA_BTC(i) | AT_DMA_ERR(i))) { |
dc78baa2b dmaengine: at_hdm... |
530 531 |
if (pending & AT_DMA_ERR(i)) { /* Disable channel on AHB error */ |
23b5e3ad6 dmaengine: at_hdm... |
532 533 |
dma_writel(atdma, CHDR, AT_DMA_RES(i) | atchan->mask); |
dc78baa2b dmaengine: at_hdm... |
534 |
/* Give information to tasklet */ |
53830cc75 dmaengine: at_hdm... |
535 |
set_bit(ATC_IS_ERROR, &atchan->status); |
dc78baa2b dmaengine: at_hdm... |
536 |
} |
d48de6f1a DMA: AT91: Get re... |
537 538 |
if (pending & AT_DMA_BTC(i)) set_bit(ATC_IS_BTC, &atchan->status); |
dc78baa2b dmaengine: at_hdm... |
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
tasklet_schedule(&atchan->tasklet); ret = IRQ_HANDLED; } } } while (pending); return ret; } /*-- DMA Engine API --------------------------------------------------*/ /** * atc_tx_submit - set the prepared descriptor(s) to be executed by the engine * @desc: descriptor at the head of the transaction chain * * Queue chain if DMA engine is working already * * Cookie increment and adding to active_list or queue must be atomic */ static dma_cookie_t atc_tx_submit(struct dma_async_tx_descriptor *tx) { struct at_desc *desc = txd_to_at_desc(tx); struct at_dma_chan *atchan = to_at_dma_chan(tx->chan); dma_cookie_t cookie; |
d8cb04b07 dmaengine: at_hdm... |
565 |
unsigned long flags; |
dc78baa2b dmaengine: at_hdm... |
566 |
|
d8cb04b07 dmaengine: at_hdm... |
567 |
spin_lock_irqsave(&atchan->lock, flags); |
884485e1f dmaengine: consol... |
568 |
cookie = dma_cookie_assign(tx); |
dc78baa2b dmaengine: at_hdm... |
569 570 571 572 573 574 575 576 577 578 579 580 581 |
if (list_empty(&atchan->active_list)) { dev_vdbg(chan2dev(tx->chan), "tx_submit: started %u ", desc->txd.cookie); atc_dostart(atchan, desc); list_add_tail(&desc->desc_node, &atchan->active_list); } else { dev_vdbg(chan2dev(tx->chan), "tx_submit: queued %u ", desc->txd.cookie); list_add_tail(&desc->desc_node, &atchan->queue); } |
d8cb04b07 dmaengine: at_hdm... |
582 |
spin_unlock_irqrestore(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
return cookie; } /** * atc_prep_dma_memcpy - prepare a memcpy operation * @chan: the channel to prepare operation on * @dest: operation virtual destination address * @src: operation virtual source address * @len: operation length * @flags: tx descriptor status flags */ static struct dma_async_tx_descriptor * atc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, size_t len, unsigned long flags) { struct at_dma_chan *atchan = to_at_dma_chan(chan); struct at_desc *desc = NULL; struct at_desc *first = NULL; struct at_desc *prev = NULL; size_t xfer_count; size_t offset; unsigned int src_width; unsigned int dst_width; u32 ctrla; u32 ctrlb; dev_vdbg(chan2dev(chan), "prep_dma_memcpy: d0x%x s0x%x l0x%zx f0x%lx ", dest, src, len, flags); if (unlikely(!len)) { dev_dbg(chan2dev(chan), "prep_dma_memcpy: length is zero! "); return NULL; } |
9b3aa589e dmaengine: at_hdm... |
619 |
ctrlb = ATC_DEFAULT_CTRLB | ATC_IEN |
dc78baa2b dmaengine: at_hdm... |
620 621 622 623 624 625 626 627 628 |
| ATC_SRC_ADDR_MODE_INCR | ATC_DST_ADDR_MODE_INCR | ATC_FC_MEM2MEM; /* * We can be a lot more clever here, but this should take care * of the most common optimization. */ if (!((src | dest | len) & 3)) { |
b409ebfb1 dmaengine: at_hdm... |
629 |
ctrla = ATC_SRC_WIDTH_WORD | ATC_DST_WIDTH_WORD; |
dc78baa2b dmaengine: at_hdm... |
630 631 |
src_width = dst_width = 2; } else if (!((src | dest | len) & 1)) { |
b409ebfb1 dmaengine: at_hdm... |
632 |
ctrla = ATC_SRC_WIDTH_HALFWORD | ATC_DST_WIDTH_HALFWORD; |
dc78baa2b dmaengine: at_hdm... |
633 634 |
src_width = dst_width = 1; } else { |
b409ebfb1 dmaengine: at_hdm... |
635 |
ctrla = ATC_SRC_WIDTH_BYTE | ATC_DST_WIDTH_BYTE; |
dc78baa2b dmaengine: at_hdm... |
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 |
src_width = dst_width = 0; } for (offset = 0; offset < len; offset += xfer_count << src_width) { xfer_count = min_t(size_t, (len - offset) >> src_width, ATC_BTSIZE_MAX); desc = atc_desc_get(atchan); if (!desc) goto err_desc_get; desc->lli.saddr = src + offset; desc->lli.daddr = dest + offset; desc->lli.ctrla = ctrla | xfer_count; desc->lli.ctrlb = ctrlb; desc->txd.cookie = 0; |
dc78baa2b dmaengine: at_hdm... |
653 |
|
e257e1563 dmaengine: at_hdm... |
654 |
atc_desc_chain(&first, &prev, desc); |
dc78baa2b dmaengine: at_hdm... |
655 656 657 658 659 |
} /* First descriptor of the chain embedds additional information */ first->txd.cookie = -EBUSY; first->len = len; |
d088c33b6 DMA: AT91: Get tr... |
660 |
first->tx_width = src_width; |
dc78baa2b dmaengine: at_hdm... |
661 662 663 |
/* set end-of-link to the last link descriptor of list*/ set_desc_eol(desc); |
568f7f0c2 dmaengine: at_hdm... |
664 |
first->txd.flags = flags; /* client is in control of this ack */ |
dc78baa2b dmaengine: at_hdm... |
665 666 667 668 669 670 671 |
return &first->txd; err_desc_get: atc_desc_put(atchan, first); return NULL; } |
808347f6a dmaengine: at_hdm... |
672 673 674 675 676 677 678 679 |
/** * atc_prep_slave_sg - prepare descriptors for a DMA_SLAVE transaction * @chan: DMA channel * @sgl: scatterlist to transfer to/from * @sg_len: number of entries in @scatterlist * @direction: DMA direction * @flags: tx descriptor status flags |
185ecb5f4 dmaengine: add co... |
680 |
* @context: transaction context (ignored) |
808347f6a dmaengine: at_hdm... |
681 682 683 |
*/ static struct dma_async_tx_descriptor * atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, |
db8196df4 dmaengine: move d... |
684 |
unsigned int sg_len, enum dma_transfer_direction direction, |
185ecb5f4 dmaengine: add co... |
685 |
unsigned long flags, void *context) |
808347f6a dmaengine: at_hdm... |
686 687 688 |
{ struct at_dma_chan *atchan = to_at_dma_chan(chan); struct at_dma_slave *atslave = chan->private; |
beeaa103e dmaengine: at_hdm... |
689 |
struct dma_slave_config *sconfig = &atchan->dma_sconfig; |
808347f6a dmaengine: at_hdm... |
690 691 692 693 694 695 696 697 698 699 |
struct at_desc *first = NULL; struct at_desc *prev = NULL; u32 ctrla; u32 ctrlb; dma_addr_t reg; unsigned int reg_width; unsigned int mem_width; unsigned int i; struct scatterlist *sg; size_t total_len = 0; |
cc52a10a0 dmaengine: at_hdm... |
700 701 702 |
dev_vdbg(chan2dev(chan), "prep_slave_sg (%d): %s f0x%lx ", sg_len, |
db8196df4 dmaengine: move d... |
703 |
direction == DMA_MEM_TO_DEV ? "TO DEVICE" : "FROM DEVICE", |
808347f6a dmaengine: at_hdm... |
704 705 706 |
flags); if (unlikely(!atslave || !sg_len)) { |
c618a9be0 dmaengine: at_hdm... |
707 708 |
dev_dbg(chan2dev(chan), "prep_slave_sg: sg length is zero! "); |
808347f6a dmaengine: at_hdm... |
709 710 |
return NULL; } |
1dd1ea8eb dmaengine: at_hdm... |
711 712 |
ctrla = ATC_SCSIZE(sconfig->src_maxburst) | ATC_DCSIZE(sconfig->dst_maxburst); |
ae14d4b5e dmaengine: at_hdm... |
713 |
ctrlb = ATC_IEN; |
808347f6a dmaengine: at_hdm... |
714 715 |
switch (direction) { |
db8196df4 dmaengine: move d... |
716 |
case DMA_MEM_TO_DEV: |
beeaa103e dmaengine: at_hdm... |
717 |
reg_width = convert_buswidth(sconfig->dst_addr_width); |
808347f6a dmaengine: at_hdm... |
718 719 720 |
ctrla |= ATC_DST_WIDTH(reg_width); ctrlb |= ATC_DST_ADDR_MODE_FIXED | ATC_SRC_ADDR_MODE_INCR |
ae14d4b5e dmaengine: at_hdm... |
721 |
| ATC_FC_MEM2PER |
bbe89c8e3 at_hdmac: move to... |
722 |
| ATC_SIF(atchan->mem_if) | ATC_DIF(atchan->per_if); |
beeaa103e dmaengine: at_hdm... |
723 |
reg = sconfig->dst_addr; |
808347f6a dmaengine: at_hdm... |
724 725 726 727 728 729 730 731 |
for_each_sg(sgl, sg, sg_len, i) { struct at_desc *desc; u32 len; u32 mem; desc = atc_desc_get(atchan); if (!desc) goto err_desc_get; |
0f70e8cea dmaengine: at_hdm... |
732 |
mem = sg_dma_address(sg); |
808347f6a dmaengine: at_hdm... |
733 |
len = sg_dma_len(sg); |
c45679768 dmaengine: at_hdm... |
734 735 736 737 738 739 |
if (unlikely(!len)) { dev_dbg(chan2dev(chan), "prep_slave_sg: sg(%d) data length is zero ", i); goto err; } |
808347f6a dmaengine: at_hdm... |
740 741 742 743 744 745 746 747 748 749 |
mem_width = 2; if (unlikely(mem & 3 || len & 3)) mem_width = 0; desc->lli.saddr = mem; desc->lli.daddr = reg; desc->lli.ctrla = ctrla | ATC_SRC_WIDTH(mem_width) | len >> mem_width; desc->lli.ctrlb = ctrlb; |
e257e1563 dmaengine: at_hdm... |
750 |
atc_desc_chain(&first, &prev, desc); |
808347f6a dmaengine: at_hdm... |
751 752 753 |
total_len += len; } break; |
db8196df4 dmaengine: move d... |
754 |
case DMA_DEV_TO_MEM: |
beeaa103e dmaengine: at_hdm... |
755 |
reg_width = convert_buswidth(sconfig->src_addr_width); |
808347f6a dmaengine: at_hdm... |
756 757 758 |
ctrla |= ATC_SRC_WIDTH(reg_width); ctrlb |= ATC_DST_ADDR_MODE_INCR | ATC_SRC_ADDR_MODE_FIXED |
ae14d4b5e dmaengine: at_hdm... |
759 |
| ATC_FC_PER2MEM |
bbe89c8e3 at_hdmac: move to... |
760 |
| ATC_SIF(atchan->per_if) | ATC_DIF(atchan->mem_if); |
808347f6a dmaengine: at_hdm... |
761 |
|
beeaa103e dmaengine: at_hdm... |
762 |
reg = sconfig->src_addr; |
808347f6a dmaengine: at_hdm... |
763 764 765 766 767 768 769 770 |
for_each_sg(sgl, sg, sg_len, i) { struct at_desc *desc; u32 len; u32 mem; desc = atc_desc_get(atchan); if (!desc) goto err_desc_get; |
0f70e8cea dmaengine: at_hdm... |
771 |
mem = sg_dma_address(sg); |
808347f6a dmaengine: at_hdm... |
772 |
len = sg_dma_len(sg); |
c45679768 dmaengine: at_hdm... |
773 774 775 776 777 778 |
if (unlikely(!len)) { dev_dbg(chan2dev(chan), "prep_slave_sg: sg(%d) data length is zero ", i); goto err; } |
808347f6a dmaengine: at_hdm... |
779 780 781 782 783 784 785 786 |
mem_width = 2; if (unlikely(mem & 3 || len & 3)) mem_width = 0; desc->lli.saddr = reg; desc->lli.daddr = mem; desc->lli.ctrla = ctrla | ATC_DST_WIDTH(mem_width) |
59a609d9b dmaengine: at_hdm... |
787 |
| len >> reg_width; |
808347f6a dmaengine: at_hdm... |
788 |
desc->lli.ctrlb = ctrlb; |
e257e1563 dmaengine: at_hdm... |
789 |
atc_desc_chain(&first, &prev, desc); |
808347f6a dmaengine: at_hdm... |
790 791 792 793 794 795 796 797 798 799 800 801 802 |
total_len += len; } break; default: return NULL; } /* set end-of-link to the last link descriptor of list*/ set_desc_eol(prev); /* First descriptor of the chain embedds additional information */ first->txd.cookie = -EBUSY; first->len = total_len; |
d088c33b6 DMA: AT91: Get tr... |
803 |
first->tx_width = reg_width; |
808347f6a dmaengine: at_hdm... |
804 |
|
568f7f0c2 dmaengine: at_hdm... |
805 806 |
/* first link descriptor of list is responsible of flags */ first->txd.flags = flags; /* client is in control of this ack */ |
808347f6a dmaengine: at_hdm... |
807 808 809 810 811 812 |
return &first->txd; err_desc_get: dev_err(chan2dev(chan), "not enough descriptors available "); |
c45679768 dmaengine: at_hdm... |
813 |
err: |
808347f6a dmaengine: at_hdm... |
814 815 816 |
atc_desc_put(atchan, first); return NULL; } |
53830cc75 dmaengine: at_hdm... |
817 818 819 820 821 822 |
/** * atc_dma_cyclic_check_values * Check for too big/unaligned periods and unaligned DMA buffer */ static int atc_dma_cyclic_check_values(unsigned int reg_width, dma_addr_t buf_addr, |
0e7264cc7 dma: at_hdmac: ch... |
823 |
size_t period_len) |
53830cc75 dmaengine: at_hdm... |
824 825 826 827 828 829 830 |
{ if (period_len > (ATC_BTSIZE_MAX << reg_width)) goto err_out; if (unlikely(period_len & ((1 << reg_width) - 1))) goto err_out; if (unlikely(buf_addr & ((1 << reg_width) - 1))) goto err_out; |
53830cc75 dmaengine: at_hdm... |
831 832 833 834 835 836 837 838 |
return 0; err_out: return -EINVAL; } /** |
d73111c6d dma: fix comments |
839 |
* atc_dma_cyclic_fill_desc - Fill one period descriptor |
53830cc75 dmaengine: at_hdm... |
840 841 |
*/ static int |
beeaa103e dmaengine: at_hdm... |
842 |
atc_dma_cyclic_fill_desc(struct dma_chan *chan, struct at_desc *desc, |
53830cc75 dmaengine: at_hdm... |
843 |
unsigned int period_index, dma_addr_t buf_addr, |
beeaa103e dmaengine: at_hdm... |
844 845 |
unsigned int reg_width, size_t period_len, enum dma_transfer_direction direction) |
53830cc75 dmaengine: at_hdm... |
846 |
{ |
beeaa103e dmaengine: at_hdm... |
847 |
struct at_dma_chan *atchan = to_at_dma_chan(chan); |
beeaa103e dmaengine: at_hdm... |
848 849 |
struct dma_slave_config *sconfig = &atchan->dma_sconfig; u32 ctrla; |
53830cc75 dmaengine: at_hdm... |
850 851 |
/* prepare common CRTLA value */ |
1dd1ea8eb dmaengine: at_hdm... |
852 853 |
ctrla = ATC_SCSIZE(sconfig->src_maxburst) | ATC_DCSIZE(sconfig->dst_maxburst) |
53830cc75 dmaengine: at_hdm... |
854 855 856 857 858 |
| ATC_DST_WIDTH(reg_width) | ATC_SRC_WIDTH(reg_width) | period_len >> reg_width; switch (direction) { |
db8196df4 dmaengine: move d... |
859 |
case DMA_MEM_TO_DEV: |
53830cc75 dmaengine: at_hdm... |
860 |
desc->lli.saddr = buf_addr + (period_len * period_index); |
beeaa103e dmaengine: at_hdm... |
861 |
desc->lli.daddr = sconfig->dst_addr; |
53830cc75 dmaengine: at_hdm... |
862 |
desc->lli.ctrla = ctrla; |
ae14d4b5e dmaengine: at_hdm... |
863 |
desc->lli.ctrlb = ATC_DST_ADDR_MODE_FIXED |
53830cc75 dmaengine: at_hdm... |
864 |
| ATC_SRC_ADDR_MODE_INCR |
ae14d4b5e dmaengine: at_hdm... |
865 |
| ATC_FC_MEM2PER |
bbe89c8e3 at_hdmac: move to... |
866 867 |
| ATC_SIF(atchan->mem_if) | ATC_DIF(atchan->per_if); |
53830cc75 dmaengine: at_hdm... |
868 |
break; |
db8196df4 dmaengine: move d... |
869 |
case DMA_DEV_TO_MEM: |
beeaa103e dmaengine: at_hdm... |
870 |
desc->lli.saddr = sconfig->src_addr; |
53830cc75 dmaengine: at_hdm... |
871 872 |
desc->lli.daddr = buf_addr + (period_len * period_index); desc->lli.ctrla = ctrla; |
ae14d4b5e dmaengine: at_hdm... |
873 |
desc->lli.ctrlb = ATC_DST_ADDR_MODE_INCR |
53830cc75 dmaengine: at_hdm... |
874 |
| ATC_SRC_ADDR_MODE_FIXED |
ae14d4b5e dmaengine: at_hdm... |
875 |
| ATC_FC_PER2MEM |
bbe89c8e3 at_hdmac: move to... |
876 877 |
| ATC_SIF(atchan->per_if) | ATC_DIF(atchan->mem_if); |
53830cc75 dmaengine: at_hdm... |
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 |
break; default: return -EINVAL; } return 0; } /** * atc_prep_dma_cyclic - prepare the cyclic DMA transfer * @chan: the DMA channel to prepare * @buf_addr: physical DMA address where the buffer starts * @buf_len: total number of bytes for the entire buffer * @period_len: number of bytes for each period * @direction: transfer direction, to or from device |
ec8b5e48c dmaengine: Pass f... |
894 |
* @flags: tx descriptor status flags |
185ecb5f4 dmaengine: add co... |
895 |
* @context: transfer context (ignored) |
53830cc75 dmaengine: at_hdm... |
896 897 898 |
*/ static struct dma_async_tx_descriptor * atc_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, |
185ecb5f4 dmaengine: add co... |
899 |
size_t period_len, enum dma_transfer_direction direction, |
ec8b5e48c dmaengine: Pass f... |
900 |
unsigned long flags, void *context) |
53830cc75 dmaengine: at_hdm... |
901 902 903 |
{ struct at_dma_chan *atchan = to_at_dma_chan(chan); struct at_dma_slave *atslave = chan->private; |
beeaa103e dmaengine: at_hdm... |
904 |
struct dma_slave_config *sconfig = &atchan->dma_sconfig; |
53830cc75 dmaengine: at_hdm... |
905 906 907 |
struct at_desc *first = NULL; struct at_desc *prev = NULL; unsigned long was_cyclic; |
beeaa103e dmaengine: at_hdm... |
908 |
unsigned int reg_width; |
53830cc75 dmaengine: at_hdm... |
909 910 911 912 913 |
unsigned int periods = buf_len / period_len; unsigned int i; dev_vdbg(chan2dev(chan), "prep_dma_cyclic: %s buf@0x%08x - %d (%d/%d) ", |
db8196df4 dmaengine: move d... |
914 |
direction == DMA_MEM_TO_DEV ? "TO DEVICE" : "FROM DEVICE", |
53830cc75 dmaengine: at_hdm... |
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 |
buf_addr, periods, buf_len, period_len); if (unlikely(!atslave || !buf_len || !period_len)) { dev_dbg(chan2dev(chan), "prep_dma_cyclic: length is zero! "); return NULL; } was_cyclic = test_and_set_bit(ATC_IS_CYCLIC, &atchan->status); if (was_cyclic) { dev_dbg(chan2dev(chan), "prep_dma_cyclic: channel in use! "); return NULL; } |
0e7264cc7 dma: at_hdmac: ch... |
930 931 |
if (unlikely(!is_slave_direction(direction))) goto err_out; |
beeaa103e dmaengine: at_hdm... |
932 933 934 935 |
if (sconfig->direction == DMA_MEM_TO_DEV) reg_width = convert_buswidth(sconfig->dst_addr_width); else reg_width = convert_buswidth(sconfig->src_addr_width); |
53830cc75 dmaengine: at_hdm... |
936 |
/* Check for too big/unaligned periods and unaligned DMA buffer */ |
0e7264cc7 dma: at_hdmac: ch... |
937 |
if (atc_dma_cyclic_check_values(reg_width, buf_addr, period_len)) |
53830cc75 dmaengine: at_hdm... |
938 939 940 941 942 943 944 945 946 |
goto err_out; /* build cyclic linked list */ for (i = 0; i < periods; i++) { struct at_desc *desc; desc = atc_desc_get(atchan); if (!desc) goto err_desc_get; |
beeaa103e dmaengine: at_hdm... |
947 948 |
if (atc_dma_cyclic_fill_desc(chan, desc, i, buf_addr, reg_width, period_len, direction)) |
53830cc75 dmaengine: at_hdm... |
949 950 951 952 953 954 955 956 957 958 959 |
goto err_desc_get; atc_desc_chain(&first, &prev, desc); } /* lets make a cyclic list */ prev->lli.dscr = first->txd.phys; /* First descriptor of the chain embedds additional information */ first->txd.cookie = -EBUSY; first->len = buf_len; |
d088c33b6 DMA: AT91: Get tr... |
960 |
first->tx_width = reg_width; |
53830cc75 dmaengine: at_hdm... |
961 962 963 964 965 966 967 968 969 970 971 |
return &first->txd; err_desc_get: dev_err(chan2dev(chan), "not enough descriptors available "); atc_desc_put(atchan, first); err_out: clear_bit(ATC_IS_CYCLIC, &atchan->status); return NULL; } |
beeaa103e dmaengine: at_hdm... |
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 |
static int set_runtime_config(struct dma_chan *chan, struct dma_slave_config *sconfig) { struct at_dma_chan *atchan = to_at_dma_chan(chan); /* Check if it is chan is configured for slave transfers */ if (!chan->private) return -EINVAL; memcpy(&atchan->dma_sconfig, sconfig, sizeof(*sconfig)); convert_burst(&atchan->dma_sconfig.src_maxburst); convert_burst(&atchan->dma_sconfig.dst_maxburst); return 0; } |
53830cc75 dmaengine: at_hdm... |
988 |
|
058276303 DMAENGINE: extend... |
989 990 |
static int atc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, unsigned long arg) |
808347f6a dmaengine: at_hdm... |
991 992 993 |
{ struct at_dma_chan *atchan = to_at_dma_chan(chan); struct at_dma *atdma = to_at_dma(chan->device); |
23b5e3ad6 dmaengine: at_hdm... |
994 |
int chan_id = atchan->chan_common.chan_id; |
d8cb04b07 dmaengine: at_hdm... |
995 |
unsigned long flags; |
23b5e3ad6 dmaengine: at_hdm... |
996 |
|
808347f6a dmaengine: at_hdm... |
997 |
LIST_HEAD(list); |
23b5e3ad6 dmaengine: at_hdm... |
998 999 |
dev_vdbg(chan2dev(chan), "atc_control (%d) ", cmd); |
c3635c78e DMAENGINE: generi... |
1000 |
|
23b5e3ad6 dmaengine: at_hdm... |
1001 |
if (cmd == DMA_PAUSE) { |
d8cb04b07 dmaengine: at_hdm... |
1002 |
spin_lock_irqsave(&atchan->lock, flags); |
808347f6a dmaengine: at_hdm... |
1003 |
|
23b5e3ad6 dmaengine: at_hdm... |
1004 |
dma_writel(atdma, CHER, AT_DMA_SUSP(chan_id)); |
23b5e3ad6 dmaengine: at_hdm... |
1005 |
set_bit(ATC_IS_PAUSED, &atchan->status); |
808347f6a dmaengine: at_hdm... |
1006 |
|
d8cb04b07 dmaengine: at_hdm... |
1007 |
spin_unlock_irqrestore(&atchan->lock, flags); |
23b5e3ad6 dmaengine: at_hdm... |
1008 |
} else if (cmd == DMA_RESUME) { |
3c477482b dmaengine: at_hdm... |
1009 |
if (!atc_chan_is_paused(atchan)) |
23b5e3ad6 dmaengine: at_hdm... |
1010 |
return 0; |
808347f6a dmaengine: at_hdm... |
1011 |
|
d8cb04b07 dmaengine: at_hdm... |
1012 |
spin_lock_irqsave(&atchan->lock, flags); |
808347f6a dmaengine: at_hdm... |
1013 |
|
23b5e3ad6 dmaengine: at_hdm... |
1014 1015 |
dma_writel(atdma, CHDR, AT_DMA_RES(chan_id)); clear_bit(ATC_IS_PAUSED, &atchan->status); |
c3635c78e DMAENGINE: generi... |
1016 |
|
d8cb04b07 dmaengine: at_hdm... |
1017 |
spin_unlock_irqrestore(&atchan->lock, flags); |
23b5e3ad6 dmaengine: at_hdm... |
1018 1019 1020 1021 1022 1023 1024 1025 |
} else if (cmd == DMA_TERMINATE_ALL) { struct at_desc *desc, *_desc; /* * This is only called when something went wrong elsewhere, so * we don't really care about the data. Just disable the * channel. We still have to poll the channel enable bit due * to AHB/HSB limitations. */ |
d8cb04b07 dmaengine: at_hdm... |
1026 |
spin_lock_irqsave(&atchan->lock, flags); |
23b5e3ad6 dmaengine: at_hdm... |
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 |
/* disabling channel: must also remove suspend state */ dma_writel(atdma, CHDR, AT_DMA_RES(chan_id) | atchan->mask); /* confirm that this channel is disabled */ while (dma_readl(atdma, CHSR) & atchan->mask) cpu_relax(); /* active_list entries will end up before queued entries */ list_splice_init(&atchan->queue, &list); list_splice_init(&atchan->active_list, &list); /* Flush all pending and queued descriptors */ list_for_each_entry_safe(desc, _desc, &list, desc_node) atc_chain_complete(atchan, desc); clear_bit(ATC_IS_PAUSED, &atchan->status); /* if channel dedicated to cyclic operations, free it */ clear_bit(ATC_IS_CYCLIC, &atchan->status); |
d8cb04b07 dmaengine: at_hdm... |
1046 |
spin_unlock_irqrestore(&atchan->lock, flags); |
beeaa103e dmaengine: at_hdm... |
1047 1048 |
} else if (cmd == DMA_SLAVE_CONFIG) { return set_runtime_config(chan, (struct dma_slave_config *)arg); |
23b5e3ad6 dmaengine: at_hdm... |
1049 1050 1051 |
} else { return -ENXIO; } |
b0ebeb9c0 DMAENGINE: at_hdm... |
1052 |
|
c3635c78e DMAENGINE: generi... |
1053 |
return 0; |
808347f6a dmaengine: at_hdm... |
1054 |
} |
dc78baa2b dmaengine: at_hdm... |
1055 |
/** |
079344818 DMAENGINE: generi... |
1056 |
* atc_tx_status - poll for transaction completion |
dc78baa2b dmaengine: at_hdm... |
1057 1058 |
* @chan: DMA channel * @cookie: transaction identifier to check status of |
079344818 DMAENGINE: generi... |
1059 |
* @txstate: if not %NULL updated with transaction state |
dc78baa2b dmaengine: at_hdm... |
1060 |
* |
079344818 DMAENGINE: generi... |
1061 |
* If @txstate is passed in, upon return it reflect the driver |
dc78baa2b dmaengine: at_hdm... |
1062 1063 1064 1065 |
* internal state and can be used with dma_async_is_complete() to check * the status of multiple cookies without re-checking hardware state. */ static enum dma_status |
079344818 DMAENGINE: generi... |
1066 |
atc_tx_status(struct dma_chan *chan, |
dc78baa2b dmaengine: at_hdm... |
1067 |
dma_cookie_t cookie, |
079344818 DMAENGINE: generi... |
1068 |
struct dma_tx_state *txstate) |
dc78baa2b dmaengine: at_hdm... |
1069 1070 |
{ struct at_dma_chan *atchan = to_at_dma_chan(chan); |
d8cb04b07 dmaengine: at_hdm... |
1071 |
unsigned long flags; |
dc78baa2b dmaengine: at_hdm... |
1072 |
enum dma_status ret; |
d48de6f1a DMA: AT91: Get re... |
1073 |
int bytes = 0; |
dc78baa2b dmaengine: at_hdm... |
1074 |
|
96a2af41c dmaengine: consol... |
1075 |
ret = dma_cookie_status(chan, cookie, txstate); |
6d203d1e0 dmaengine: at_hdm... |
1076 |
if (ret == DMA_COMPLETE) |
d48de6f1a DMA: AT91: Get re... |
1077 1078 1079 1080 1081 1082 1083 |
return ret; /* * There's no point calculating the residue if there's * no txstate to store the value. */ if (!txstate) return DMA_ERROR; |
dc78baa2b dmaengine: at_hdm... |
1084 |
|
d48de6f1a DMA: AT91: Get re... |
1085 |
spin_lock_irqsave(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
1086 |
|
d48de6f1a DMA: AT91: Get re... |
1087 1088 |
/* Get number of bytes left in the active transactions */ bytes = atc_get_bytes_left(chan); |
96a2af41c dmaengine: consol... |
1089 |
|
d8cb04b07 dmaengine: at_hdm... |
1090 |
spin_unlock_irqrestore(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
1091 |
|
d48de6f1a DMA: AT91: Get re... |
1092 1093 1094 1095 |
if (unlikely(bytes < 0)) { dev_vdbg(chan2dev(chan), "get residual bytes error "); return DMA_ERROR; |
c3dbc60c9 dmaengine/trivial... |
1096 |
} else { |
d48de6f1a DMA: AT91: Get re... |
1097 |
dma_set_residue(txstate, bytes); |
c3dbc60c9 dmaengine/trivial... |
1098 |
} |
23b5e3ad6 dmaengine: at_hdm... |
1099 |
|
d48de6f1a DMA: AT91: Get re... |
1100 1101 1102 |
dev_vdbg(chan2dev(chan), "tx_status %d: cookie = %d residue = %d ", ret, cookie, bytes); |
dc78baa2b dmaengine: at_hdm... |
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 |
return ret; } /** * atc_issue_pending - try to finish work * @chan: target DMA channel */ static void atc_issue_pending(struct dma_chan *chan) { struct at_dma_chan *atchan = to_at_dma_chan(chan); |
d8cb04b07 dmaengine: at_hdm... |
1114 |
unsigned long flags; |
dc78baa2b dmaengine: at_hdm... |
1115 1116 1117 |
dev_vdbg(chan2dev(chan), "issue_pending "); |
53830cc75 dmaengine: at_hdm... |
1118 |
/* Not needed for cyclic transfers */ |
3c477482b dmaengine: at_hdm... |
1119 |
if (atc_chan_is_cyclic(atchan)) |
53830cc75 dmaengine: at_hdm... |
1120 |
return; |
d8cb04b07 dmaengine: at_hdm... |
1121 |
spin_lock_irqsave(&atchan->lock, flags); |
d202f0515 dmaengine: at_hdm... |
1122 |
atc_advance_work(atchan); |
d8cb04b07 dmaengine: at_hdm... |
1123 |
spin_unlock_irqrestore(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 |
} /** * atc_alloc_chan_resources - allocate resources for DMA channel * @chan: allocate descriptor resources for this channel * @client: current client requesting the channel be ready for requests * * return - the number of allocated descriptors */ static int atc_alloc_chan_resources(struct dma_chan *chan) { struct at_dma_chan *atchan = to_at_dma_chan(chan); struct at_dma *atdma = to_at_dma(chan->device); struct at_desc *desc; |
808347f6a dmaengine: at_hdm... |
1138 |
struct at_dma_slave *atslave; |
d8cb04b07 dmaengine: at_hdm... |
1139 |
unsigned long flags; |
dc78baa2b dmaengine: at_hdm... |
1140 |
int i; |
808347f6a dmaengine: at_hdm... |
1141 |
u32 cfg; |
dc78baa2b dmaengine: at_hdm... |
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 |
LIST_HEAD(tmp_list); dev_vdbg(chan2dev(chan), "alloc_chan_resources "); /* ASSERT: channel is idle */ if (atc_chan_is_enabled(atchan)) { dev_dbg(chan2dev(chan), "DMA channel not idle ? "); return -EIO; } |
808347f6a dmaengine: at_hdm... |
1153 1154 1155 1156 1157 1158 1159 1160 1161 |
cfg = ATC_DEFAULT_CFG; atslave = chan->private; if (atslave) { /* * We need controller-specific data to set up slave * transfers. */ BUG_ON(!atslave->dma_dev || atslave->dma_dev != atdma->dma_common.dev); |
ea7e79063 dmaengine: at_hdm... |
1162 |
/* if cfg configuration specified take it instead of default */ |
808347f6a dmaengine: at_hdm... |
1163 1164 1165 1166 1167 1168 |
if (atslave->cfg) cfg = atslave->cfg; } /* have we already been set up? * reconfigure channel but no need to reallocate descriptors */ |
dc78baa2b dmaengine: at_hdm... |
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 |
if (!list_empty(&atchan->free_list)) return atchan->descs_allocated; /* Allocate initial pool of descriptors */ for (i = 0; i < init_nr_desc_per_channel; i++) { desc = atc_alloc_descriptor(chan, GFP_KERNEL); if (!desc) { dev_err(atdma->dma_common.dev, "Only %d initial descriptors ", i); break; } list_add_tail(&desc->desc_node, &tmp_list); } |
d8cb04b07 dmaengine: at_hdm... |
1183 |
spin_lock_irqsave(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
1184 |
atchan->descs_allocated = i; |
d48de6f1a DMA: AT91: Get re... |
1185 |
atchan->remain_desc = 0; |
dc78baa2b dmaengine: at_hdm... |
1186 |
list_splice(&tmp_list, &atchan->free_list); |
d3ee98cdc dmaengine: consol... |
1187 |
dma_cookie_init(chan); |
d8cb04b07 dmaengine: at_hdm... |
1188 |
spin_unlock_irqrestore(&atchan->lock, flags); |
dc78baa2b dmaengine: at_hdm... |
1189 1190 |
/* channel parameters */ |
808347f6a dmaengine: at_hdm... |
1191 |
channel_writel(atchan, CFG, cfg); |
dc78baa2b dmaengine: at_hdm... |
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 |
dev_dbg(chan2dev(chan), "alloc_chan_resources: allocated %d descriptors ", atchan->descs_allocated); return atchan->descs_allocated; } /** * atc_free_chan_resources - free all channel resources * @chan: DMA channel */ static void atc_free_chan_resources(struct dma_chan *chan) { struct at_dma_chan *atchan = to_at_dma_chan(chan); struct at_dma *atdma = to_at_dma(chan->device); struct at_desc *desc, *_desc; LIST_HEAD(list); dev_dbg(chan2dev(chan), "free_chan_resources: (descs allocated=%u) ", atchan->descs_allocated); /* ASSERT: channel is idle */ BUG_ON(!list_empty(&atchan->active_list)); BUG_ON(!list_empty(&atchan->queue)); BUG_ON(atc_chan_is_enabled(atchan)); list_for_each_entry_safe(desc, _desc, &atchan->free_list, desc_node) { dev_vdbg(chan2dev(chan), " freeing descriptor %p ", desc); list_del(&desc->desc_node); /* free link descriptor */ dma_pool_free(atdma->dma_desc_pool, desc, desc->txd.phys); } list_splice_init(&atchan->free_list, &list); atchan->descs_allocated = 0; |
53830cc75 dmaengine: at_hdm... |
1230 |
atchan->status = 0; |
d48de6f1a DMA: AT91: Get re... |
1231 |
atchan->remain_desc = 0; |
dc78baa2b dmaengine: at_hdm... |
1232 1233 1234 1235 |
dev_vdbg(chan2dev(chan), "free_chan_resources: done "); } |
bbe89c8e3 at_hdmac: move to... |
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 |
#ifdef CONFIG_OF static bool at_dma_filter(struct dma_chan *chan, void *slave) { struct at_dma_slave *atslave = slave; if (atslave->dma_dev == chan->device->dev) { chan->private = atslave; return true; } else { return false; } } static struct dma_chan *at_dma_xlate(struct of_phandle_args *dma_spec, struct of_dma *of_dma) { struct dma_chan *chan; struct at_dma_chan *atchan; struct at_dma_slave *atslave; dma_cap_mask_t mask; unsigned int per_id; struct platform_device *dmac_pdev; if (dma_spec->args_count != 2) return NULL; dmac_pdev = of_find_device_by_node(dma_spec->np); dma_cap_zero(mask); dma_cap_set(DMA_SLAVE, mask); atslave = devm_kzalloc(&dmac_pdev->dev, sizeof(*atslave), GFP_KERNEL); if (!atslave) return NULL; |
62971b298 dmaengine: at_hdm... |
1270 1271 |
atslave->cfg = ATC_DST_H2SEL_HW | ATC_SRC_H2SEL_HW; |
bbe89c8e3 at_hdmac: move to... |
1272 1273 1274 1275 |
/* * We can fill both SRC_PER and DST_PER, one of these fields will be * ignored depending on DMA transfer direction. */ |
62971b298 dmaengine: at_hdm... |
1276 1277 |
per_id = dma_spec->args[1] & AT91_DMA_CFG_PER_ID_MASK; atslave->cfg |= ATC_DST_PER_MSB(per_id) | ATC_DST_PER(per_id) |
6c22770f6 dmaengine: at_hdm... |
1278 |
| ATC_SRC_PER_MSB(per_id) | ATC_SRC_PER(per_id); |
62971b298 dmaengine: at_hdm... |
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 |
/* * We have to translate the value we get from the device tree since * the half FIFO configuration value had to be 0 to keep backward * compatibility. */ switch (dma_spec->args[1] & AT91_DMA_CFG_FIFOCFG_MASK) { case AT91_DMA_CFG_FIFOCFG_ALAP: atslave->cfg |= ATC_FIFOCFG_LARGESTBURST; break; case AT91_DMA_CFG_FIFOCFG_ASAP: atslave->cfg |= ATC_FIFOCFG_ENOUGHSPACE; break; case AT91_DMA_CFG_FIFOCFG_HALF: default: atslave->cfg |= ATC_FIFOCFG_HALFFIFO; } |
bbe89c8e3 at_hdmac: move to... |
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 |
atslave->dma_dev = &dmac_pdev->dev; chan = dma_request_channel(mask, at_dma_filter, atslave); if (!chan) return NULL; atchan = to_at_dma_chan(chan); atchan->per_if = dma_spec->args[0] & 0xff; atchan->mem_if = (dma_spec->args[0] >> 16) & 0xff; return chan; } #else static struct dma_chan *at_dma_xlate(struct of_phandle_args *dma_spec, struct of_dma *of_dma) { return NULL; } #endif |
dc78baa2b dmaengine: at_hdm... |
1314 1315 |
/*-- Module Management -----------------------------------------------*/ |
02f88be94 dmaengine: at_hdm... |
1316 1317 1318 1319 1320 1321 1322 |
/* cap_mask is a multi-u32 bitfield, fill it with proper C code. */ static struct at_dma_platform_data at91sam9rl_config = { .nr_channels = 2, }; static struct at_dma_platform_data at91sam9g45_config = { .nr_channels = 8, }; |
c51159539 dmaengine: at_hdm... |
1323 1324 1325 1326 |
#if defined(CONFIG_OF) static const struct of_device_id atmel_dma_dt_ids[] = { { .compatible = "atmel,at91sam9rl-dma", |
02f88be94 dmaengine: at_hdm... |
1327 |
.data = &at91sam9rl_config, |
c51159539 dmaengine: at_hdm... |
1328 1329 |
}, { .compatible = "atmel,at91sam9g45-dma", |
02f88be94 dmaengine: at_hdm... |
1330 |
.data = &at91sam9g45_config, |
dcc817346 dmaengine: at_hdm... |
1331 1332 1333 |
}, { /* sentinel */ } |
c51159539 dmaengine: at_hdm... |
1334 1335 1336 1337 |
}; MODULE_DEVICE_TABLE(of, atmel_dma_dt_ids); #endif |
0ab88a018 dmaengine: at_hdm... |
1338 |
static const struct platform_device_id atdma_devtypes[] = { |
67348450b dmaengine: at_hdm... |
1339 1340 |
{ .name = "at91sam9rl_dma", |
02f88be94 dmaengine: at_hdm... |
1341 |
.driver_data = (unsigned long) &at91sam9rl_config, |
67348450b dmaengine: at_hdm... |
1342 1343 |
}, { .name = "at91sam9g45_dma", |
02f88be94 dmaengine: at_hdm... |
1344 |
.driver_data = (unsigned long) &at91sam9g45_config, |
67348450b dmaengine: at_hdm... |
1345 1346 1347 1348 |
}, { /* sentinel */ } }; |
7fd63ccda dmaengine: at_hdm... |
1349 |
static inline const struct at_dma_platform_data * __init at_dma_get_driver_data( |
02f88be94 dmaengine: at_hdm... |
1350 |
struct platform_device *pdev) |
c51159539 dmaengine: at_hdm... |
1351 1352 1353 1354 1355 |
{ if (pdev->dev.of_node) { const struct of_device_id *match; match = of_match_node(atmel_dma_dt_ids, pdev->dev.of_node); if (match == NULL) |
02f88be94 dmaengine: at_hdm... |
1356 1357 |
return NULL; return match->data; |
c51159539 dmaengine: at_hdm... |
1358 |
} |
02f88be94 dmaengine: at_hdm... |
1359 1360 |
return (struct at_dma_platform_data *) platform_get_device_id(pdev)->driver_data; |
c51159539 dmaengine: at_hdm... |
1361 |
} |
dc78baa2b dmaengine: at_hdm... |
1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 |
/** * at_dma_off - disable DMA controller * @atdma: the Atmel HDAMC device */ static void at_dma_off(struct at_dma *atdma) { dma_writel(atdma, EN, 0); /* disable all interrupts */ dma_writel(atdma, EBCIDR, -1L); /* confirm that all channels are disabled */ while (dma_readl(atdma, CHSR) & atdma->all_chan_mask) cpu_relax(); } static int __init at_dma_probe(struct platform_device *pdev) { |
dc78baa2b dmaengine: at_hdm... |
1380 1381 1382 1383 1384 1385 |
struct resource *io; struct at_dma *atdma; size_t size; int irq; int err; int i; |
7fd63ccda dmaengine: at_hdm... |
1386 |
const struct at_dma_platform_data *plat_dat; |
67348450b dmaengine: at_hdm... |
1387 |
|
02f88be94 dmaengine: at_hdm... |
1388 1389 1390 1391 |
/* setup platform data for each SoC */ dma_cap_set(DMA_MEMCPY, at91sam9rl_config.cap_mask); dma_cap_set(DMA_MEMCPY, at91sam9g45_config.cap_mask); dma_cap_set(DMA_SLAVE, at91sam9g45_config.cap_mask); |
67348450b dmaengine: at_hdm... |
1392 1393 |
/* get DMA parameters from controller type */ |
02f88be94 dmaengine: at_hdm... |
1394 1395 1396 |
plat_dat = at_dma_get_driver_data(pdev); if (!plat_dat) return -ENODEV; |
dc78baa2b dmaengine: at_hdm... |
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 |
io = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!io) return -EINVAL; irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; size = sizeof(struct at_dma); |
02f88be94 dmaengine: at_hdm... |
1407 |
size += plat_dat->nr_channels * sizeof(struct at_dma_chan); |
dc78baa2b dmaengine: at_hdm... |
1408 1409 1410 |
atdma = kzalloc(size, GFP_KERNEL); if (!atdma) return -ENOMEM; |
67348450b dmaengine: at_hdm... |
1411 |
/* discover transaction capabilities */ |
02f88be94 dmaengine: at_hdm... |
1412 1413 |
atdma->dma_common.cap_mask = plat_dat->cap_mask; atdma->all_chan_mask = (1 << plat_dat->nr_channels) - 1; |
dc78baa2b dmaengine: at_hdm... |
1414 |
|
114df7d66 dma: at_hdmac.c: ... |
1415 |
size = resource_size(io); |
dc78baa2b dmaengine: at_hdm... |
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 |
if (!request_mem_region(io->start, size, pdev->dev.driver->name)) { err = -EBUSY; goto err_kfree; } atdma->regs = ioremap(io->start, size); if (!atdma->regs) { err = -ENOMEM; goto err_release_r; } atdma->clk = clk_get(&pdev->dev, "dma_clk"); if (IS_ERR(atdma->clk)) { err = PTR_ERR(atdma->clk); goto err_clk; } |
f784d9c90 dmaengine: at_hdm... |
1432 1433 1434 |
err = clk_prepare_enable(atdma->clk); if (err) goto err_clk_prepare; |
dc78baa2b dmaengine: at_hdm... |
1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 |
/* force dma off, just in case */ at_dma_off(atdma); err = request_irq(irq, at_dma_interrupt, 0, "at_hdmac", atdma); if (err) goto err_irq; platform_set_drvdata(pdev, atdma); /* create a pool of consistent memory blocks for hardware descriptors */ atdma->dma_desc_pool = dma_pool_create("at_hdmac_desc_pool", &pdev->dev, sizeof(struct at_desc), 4 /* word alignment */, 0); if (!atdma->dma_desc_pool) { dev_err(&pdev->dev, "No memory for descriptors dma pool "); err = -ENOMEM; goto err_pool_create; } /* clear any pending interrupt */ while (dma_readl(atdma, EBCISR)) cpu_relax(); /* initialize channels related values */ INIT_LIST_HEAD(&atdma->dma_common.channels); |
02f88be94 dmaengine: at_hdm... |
1462 |
for (i = 0; i < plat_dat->nr_channels; i++) { |
dc78baa2b dmaengine: at_hdm... |
1463 |
struct at_dma_chan *atchan = &atdma->chan[i]; |
bbe89c8e3 at_hdmac: move to... |
1464 1465 |
atchan->mem_if = AT_DMA_MEM_IF; atchan->per_if = AT_DMA_PER_IF; |
dc78baa2b dmaengine: at_hdm... |
1466 |
atchan->chan_common.device = &atdma->dma_common; |
d3ee98cdc dmaengine: consol... |
1467 |
dma_cookie_init(&atchan->chan_common); |
dc78baa2b dmaengine: at_hdm... |
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 |
list_add_tail(&atchan->chan_common.device_node, &atdma->dma_common.channels); atchan->ch_regs = atdma->regs + ch_regs(i); spin_lock_init(&atchan->lock); atchan->mask = 1 << i; INIT_LIST_HEAD(&atchan->active_list); INIT_LIST_HEAD(&atchan->queue); INIT_LIST_HEAD(&atchan->free_list); tasklet_init(&atchan->tasklet, atc_tasklet, (unsigned long)atchan); |
bda3a47c8 at_hdmac: bugfix ... |
1481 |
atc_enable_chan_irq(atdma, i); |
dc78baa2b dmaengine: at_hdm... |
1482 1483 1484 1485 1486 |
} /* set base routines */ atdma->dma_common.device_alloc_chan_resources = atc_alloc_chan_resources; atdma->dma_common.device_free_chan_resources = atc_free_chan_resources; |
079344818 DMAENGINE: generi... |
1487 |
atdma->dma_common.device_tx_status = atc_tx_status; |
dc78baa2b dmaengine: at_hdm... |
1488 1489 1490 1491 1492 1493 |
atdma->dma_common.device_issue_pending = atc_issue_pending; atdma->dma_common.dev = &pdev->dev; /* set prep routines based on capability */ if (dma_has_cap(DMA_MEMCPY, atdma->dma_common.cap_mask)) atdma->dma_common.device_prep_dma_memcpy = atc_prep_dma_memcpy; |
d7db80801 dmaengine: at_hdm... |
1494 |
if (dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask)) { |
808347f6a dmaengine: at_hdm... |
1495 |
atdma->dma_common.device_prep_slave_sg = atc_prep_slave_sg; |
d7db80801 dmaengine: at_hdm... |
1496 1497 |
/* controller can do slave DMA: can trigger cyclic transfers */ dma_cap_set(DMA_CYCLIC, atdma->dma_common.cap_mask); |
53830cc75 dmaengine: at_hdm... |
1498 |
atdma->dma_common.device_prep_dma_cyclic = atc_prep_dma_cyclic; |
c3635c78e DMAENGINE: generi... |
1499 |
atdma->dma_common.device_control = atc_control; |
d7db80801 dmaengine: at_hdm... |
1500 |
} |
808347f6a dmaengine: at_hdm... |
1501 |
|
dc78baa2b dmaengine: at_hdm... |
1502 1503 1504 1505 1506 1507 |
dma_writel(atdma, EN, AT_DMA_ENABLE); dev_info(&pdev->dev, "Atmel AHB DMA Controller ( %s%s), %d channels ", dma_has_cap(DMA_MEMCPY, atdma->dma_common.cap_mask) ? "cpy " : "", dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask) ? "slave " : "", |
02f88be94 dmaengine: at_hdm... |
1508 |
plat_dat->nr_channels); |
dc78baa2b dmaengine: at_hdm... |
1509 1510 |
dma_async_device_register(&atdma->dma_common); |
bbe89c8e3 at_hdmac: move to... |
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 |
/* * Do not return an error if the dmac node is not present in order to * not break the existing way of requesting channel with * dma_request_channel(). */ if (pdev->dev.of_node) { err = of_dma_controller_register(pdev->dev.of_node, at_dma_xlate, atdma); if (err) { dev_err(&pdev->dev, "could not register of_dma_controller "); goto err_of_dma_controller_register; } } |
dc78baa2b dmaengine: at_hdm... |
1525 |
return 0; |
bbe89c8e3 at_hdmac: move to... |
1526 1527 1528 |
err_of_dma_controller_register: dma_async_device_unregister(&atdma->dma_common); dma_pool_destroy(atdma->dma_desc_pool); |
dc78baa2b dmaengine: at_hdm... |
1529 |
err_pool_create: |
dc78baa2b dmaengine: at_hdm... |
1530 1531 |
free_irq(platform_get_irq(pdev, 0), atdma); err_irq: |
f784d9c90 dmaengine: at_hdm... |
1532 1533 |
clk_disable_unprepare(atdma->clk); err_clk_prepare: |
dc78baa2b dmaengine: at_hdm... |
1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 |
clk_put(atdma->clk); err_clk: iounmap(atdma->regs); atdma->regs = NULL; err_release_r: release_mem_region(io->start, size); err_kfree: kfree(atdma); return err; } |
1d1bbd305 dma: Remove erron... |
1544 |
static int at_dma_remove(struct platform_device *pdev) |
dc78baa2b dmaengine: at_hdm... |
1545 1546 1547 1548 1549 1550 1551 1552 1553 |
{ struct at_dma *atdma = platform_get_drvdata(pdev); struct dma_chan *chan, *_chan; struct resource *io; at_dma_off(atdma); dma_async_device_unregister(&atdma->dma_common); dma_pool_destroy(atdma->dma_desc_pool); |
dc78baa2b dmaengine: at_hdm... |
1554 1555 1556 1557 1558 1559 1560 |
free_irq(platform_get_irq(pdev, 0), atdma); list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels, device_node) { struct at_dma_chan *atchan = to_at_dma_chan(chan); /* Disable interrupts */ |
bda3a47c8 at_hdmac: bugfix ... |
1561 |
atc_disable_chan_irq(atdma, chan->chan_id); |
dc78baa2b dmaengine: at_hdm... |
1562 1563 1564 1565 |
tasklet_kill(&atchan->tasklet); list_del(&chan->device_node); } |
f784d9c90 dmaengine: at_hdm... |
1566 |
clk_disable_unprepare(atdma->clk); |
dc78baa2b dmaengine: at_hdm... |
1567 1568 1569 1570 1571 1572 |
clk_put(atdma->clk); iounmap(atdma->regs); atdma->regs = NULL; io = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
114df7d66 dma: at_hdmac.c: ... |
1573 |
release_mem_region(io->start, resource_size(io)); |
dc78baa2b dmaengine: at_hdm... |
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 |
kfree(atdma); return 0; } static void at_dma_shutdown(struct platform_device *pdev) { struct at_dma *atdma = platform_get_drvdata(pdev); at_dma_off(platform_get_drvdata(pdev)); |
f784d9c90 dmaengine: at_hdm... |
1585 |
clk_disable_unprepare(atdma->clk); |
dc78baa2b dmaengine: at_hdm... |
1586 |
} |
c0ba59473 dmaengine: at_hdm... |
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 |
static int at_dma_prepare(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct at_dma *atdma = platform_get_drvdata(pdev); struct dma_chan *chan, *_chan; list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels, device_node) { struct at_dma_chan *atchan = to_at_dma_chan(chan); /* wait for transaction completion (except in cyclic case) */ |
3c477482b dmaengine: at_hdm... |
1597 |
if (atc_chan_is_enabled(atchan) && !atc_chan_is_cyclic(atchan)) |
c0ba59473 dmaengine: at_hdm... |
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 |
return -EAGAIN; } return 0; } static void atc_suspend_cyclic(struct at_dma_chan *atchan) { struct dma_chan *chan = &atchan->chan_common; /* Channel should be paused by user * do it anyway even if it is not done already */ |
3c477482b dmaengine: at_hdm... |
1609 |
if (!atc_chan_is_paused(atchan)) { |
c0ba59473 dmaengine: at_hdm... |
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 |
dev_warn(chan2dev(chan), "cyclic channel not paused, should be done by channel user "); atc_control(chan, DMA_PAUSE, 0); } /* now preserve additional data for cyclic operations */ /* next descriptor address in the cyclic list */ atchan->save_dscr = channel_readl(atchan, DSCR); vdbg_dump_regs(atchan); } |
33f82d141 at_hdmac: Rework ... |
1622 |
static int at_dma_suspend_noirq(struct device *dev) |
dc78baa2b dmaengine: at_hdm... |
1623 |
{ |
33f82d141 at_hdmac: Rework ... |
1624 1625 |
struct platform_device *pdev = to_platform_device(dev); struct at_dma *atdma = platform_get_drvdata(pdev); |
c0ba59473 dmaengine: at_hdm... |
1626 |
struct dma_chan *chan, *_chan; |
dc78baa2b dmaengine: at_hdm... |
1627 |
|
c0ba59473 dmaengine: at_hdm... |
1628 1629 1630 1631 |
/* preserve data */ list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels, device_node) { struct at_dma_chan *atchan = to_at_dma_chan(chan); |
3c477482b dmaengine: at_hdm... |
1632 |
if (atc_chan_is_cyclic(atchan)) |
c0ba59473 dmaengine: at_hdm... |
1633 1634 1635 1636 1637 1638 1639 |
atc_suspend_cyclic(atchan); atchan->save_cfg = channel_readl(atchan, CFG); } atdma->save_imr = dma_readl(atdma, EBCIMR); /* disable DMA controller */ at_dma_off(atdma); |
f784d9c90 dmaengine: at_hdm... |
1640 |
clk_disable_unprepare(atdma->clk); |
dc78baa2b dmaengine: at_hdm... |
1641 1642 |
return 0; } |
c0ba59473 dmaengine: at_hdm... |
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 |
static void atc_resume_cyclic(struct at_dma_chan *atchan) { struct at_dma *atdma = to_at_dma(atchan->chan_common.device); /* restore channel status for cyclic descriptors list: * next descriptor in the cyclic list at the time of suspend */ channel_writel(atchan, SADDR, 0); channel_writel(atchan, DADDR, 0); channel_writel(atchan, CTRLA, 0); channel_writel(atchan, CTRLB, 0); channel_writel(atchan, DSCR, atchan->save_dscr); dma_writel(atdma, CHER, atchan->mask); /* channel pause status should be removed by channel user * We cannot take the initiative to do it here */ vdbg_dump_regs(atchan); } |
33f82d141 at_hdmac: Rework ... |
1661 |
static int at_dma_resume_noirq(struct device *dev) |
dc78baa2b dmaengine: at_hdm... |
1662 |
{ |
33f82d141 at_hdmac: Rework ... |
1663 1664 |
struct platform_device *pdev = to_platform_device(dev); struct at_dma *atdma = platform_get_drvdata(pdev); |
c0ba59473 dmaengine: at_hdm... |
1665 |
struct dma_chan *chan, *_chan; |
dc78baa2b dmaengine: at_hdm... |
1666 |
|
c0ba59473 dmaengine: at_hdm... |
1667 |
/* bring back DMA controller */ |
f784d9c90 dmaengine: at_hdm... |
1668 |
clk_prepare_enable(atdma->clk); |
dc78baa2b dmaengine: at_hdm... |
1669 |
dma_writel(atdma, EN, AT_DMA_ENABLE); |
c0ba59473 dmaengine: at_hdm... |
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 |
/* clear any pending interrupt */ while (dma_readl(atdma, EBCISR)) cpu_relax(); /* restore saved data */ dma_writel(atdma, EBCIER, atdma->save_imr); list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels, device_node) { struct at_dma_chan *atchan = to_at_dma_chan(chan); channel_writel(atchan, CFG, atchan->save_cfg); |
3c477482b dmaengine: at_hdm... |
1682 |
if (atc_chan_is_cyclic(atchan)) |
c0ba59473 dmaengine: at_hdm... |
1683 1684 |
atc_resume_cyclic(atchan); } |
dc78baa2b dmaengine: at_hdm... |
1685 |
return 0; |
dc78baa2b dmaengine: at_hdm... |
1686 |
} |
471452104 const: constify r... |
1687 |
static const struct dev_pm_ops at_dma_dev_pm_ops = { |
c0ba59473 dmaengine: at_hdm... |
1688 |
.prepare = at_dma_prepare, |
33f82d141 at_hdmac: Rework ... |
1689 1690 1691 |
.suspend_noirq = at_dma_suspend_noirq, .resume_noirq = at_dma_resume_noirq, }; |
dc78baa2b dmaengine: at_hdm... |
1692 |
static struct platform_driver at_dma_driver = { |
1d1bbd305 dma: Remove erron... |
1693 |
.remove = at_dma_remove, |
dc78baa2b dmaengine: at_hdm... |
1694 |
.shutdown = at_dma_shutdown, |
67348450b dmaengine: at_hdm... |
1695 |
.id_table = atdma_devtypes, |
dc78baa2b dmaengine: at_hdm... |
1696 1697 |
.driver = { .name = "at_hdmac", |
33f82d141 at_hdmac: Rework ... |
1698 |
.pm = &at_dma_dev_pm_ops, |
c51159539 dmaengine: at_hdm... |
1699 |
.of_match_table = of_match_ptr(atmel_dma_dt_ids), |
dc78baa2b dmaengine: at_hdm... |
1700 1701 1702 1703 1704 1705 1706 |
}, }; static int __init at_dma_init(void) { return platform_driver_probe(&at_dma_driver, at_dma_probe); } |
93d0bec2b dmaengine: at_hdm... |
1707 |
subsys_initcall(at_dma_init); |
dc78baa2b dmaengine: at_hdm... |
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 |
static void __exit at_dma_exit(void) { platform_driver_unregister(&at_dma_driver); } module_exit(at_dma_exit); MODULE_DESCRIPTION("Atmel AHB DMA Controller driver"); MODULE_AUTHOR("Nicolas Ferre <nicolas.ferre@atmel.com>"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:at_hdmac"); |