aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dma
diff options
context:
space:
mode:
authorVinod Koul <vinod.koul@linux.intel.com>2011-09-02 07:13:44 -0400
committerVinod Koul <vinod.koul@intel.com>2011-09-02 07:13:44 -0400
commit8516f52fa497b37eb3d5e58d34e61a41ae0a553a (patch)
treeb73175b134d36bea303d2f181ae89a448c2add81 /drivers/dma
parentc6a389f123b9f68d605bb7e0f9b32ec1e3e14132 (diff)
parent7b4b88e067d37cbbafd856121767f7e154294eb2 (diff)
Merge branch 'next' into v3.1-rc4
Fixed trivial conflicts in drivers/dma/amba-pl08x.c Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Diffstat (limited to 'drivers/dma')
-rw-r--r--drivers/dma/amba-pl08x.c445
-rw-r--r--drivers/dma/at_hdmac.c159
-rw-r--r--drivers/dma/at_hdmac_regs.h24
-rw-r--r--drivers/dma/dmatest.c23
-rw-r--r--drivers/dma/imx-sdma.c47
-rw-r--r--drivers/dma/mxs-dma.c45
6 files changed, 420 insertions, 323 deletions
diff --git a/drivers/dma/amba-pl08x.c b/drivers/dma/amba-pl08x.c
index be21e3f138a8..3c2cad5b1165 100644
--- a/drivers/dma/amba-pl08x.c
+++ b/drivers/dma/amba-pl08x.c
@@ -66,28 +66,23 @@
66 * after the final transfer signalled by LBREQ or LSREQ. The DMAC 66 * after the final transfer signalled by LBREQ or LSREQ. The DMAC
67 * will then move to the next LLI entry. 67 * will then move to the next LLI entry.
68 * 68 *
69 * Only the former works sanely with scatter lists, so we only implement
70 * the DMAC flow control method. However, peripherals which use the LBREQ
71 * and LSREQ signals (eg, MMCI) are unable to use this mode, which through
72 * these hardware restrictions prevents them from using scatter DMA.
73 *
74 * Global TODO: 69 * Global TODO:
75 * - Break out common code from arch/arm/mach-s3c64xx and share 70 * - Break out common code from arch/arm/mach-s3c64xx and share
76 */ 71 */
77#include <linux/device.h>
78#include <linux/init.h>
79#include <linux/module.h>
80#include <linux/interrupt.h>
81#include <linux/slab.h>
82#include <linux/delay.h>
83#include <linux/dma-mapping.h>
84#include <linux/dmapool.h>
85#include <linux/dmaengine.h>
86#include <linux/amba/bus.h> 72#include <linux/amba/bus.h>
87#include <linux/amba/pl08x.h> 73#include <linux/amba/pl08x.h>
88#include <linux/debugfs.h> 74#include <linux/debugfs.h>
75#include <linux/delay.h>
76#include <linux/device.h>
77#include <linux/dmaengine.h>
78#include <linux/dmapool.h>
79#include <linux/dma-mapping.h>
80#include <linux/init.h>
81#include <linux/interrupt.h>
82#include <linux/module.h>
83#include <linux/pm_runtime.h>
89#include <linux/seq_file.h> 84#include <linux/seq_file.h>
90 85#include <linux/slab.h>
91#include <asm/hardware/pl080.h> 86#include <asm/hardware/pl080.h>
92 87
93#define DRIVER_NAME "pl08xdmac" 88#define DRIVER_NAME "pl08xdmac"
@@ -126,7 +121,8 @@ struct pl08x_lli {
126 * @phy_chans: array of data for the physical channels 121 * @phy_chans: array of data for the physical channels
127 * @pool: a pool for the LLI descriptors 122 * @pool: a pool for the LLI descriptors
128 * @pool_ctr: counter of LLIs in the pool 123 * @pool_ctr: counter of LLIs in the pool
129 * @lli_buses: bitmask to or in to LLI pointer selecting AHB port for LLI fetches 124 * @lli_buses: bitmask to or in to LLI pointer selecting AHB port for LLI
125 * fetches
130 * @mem_buses: set to indicate memory transfers on AHB2. 126 * @mem_buses: set to indicate memory transfers on AHB2.
131 * @lock: a spinlock for this struct 127 * @lock: a spinlock for this struct
132 */ 128 */
@@ -149,14 +145,6 @@ struct pl08x_driver_data {
149 * PL08X specific defines 145 * PL08X specific defines
150 */ 146 */
151 147
152/*
153 * Memory boundaries: the manual for PL08x says that the controller
154 * cannot read past a 1KiB boundary, so these defines are used to
155 * create transfer LLIs that do not cross such boundaries.
156 */
157#define PL08X_BOUNDARY_SHIFT (10) /* 1KB 0x400 */
158#define PL08X_BOUNDARY_SIZE (1 << PL08X_BOUNDARY_SHIFT)
159
160/* Size (bytes) of each LLI buffer allocated for one transfer */ 148/* Size (bytes) of each LLI buffer allocated for one transfer */
161# define PL08X_LLI_TSFR_SIZE 0x2000 149# define PL08X_LLI_TSFR_SIZE 0x2000
162 150
@@ -272,7 +260,6 @@ static void pl08x_resume_phy_chan(struct pl08x_phy_chan *ch)
272 writel(val, ch->base + PL080_CH_CONFIG); 260 writel(val, ch->base + PL080_CH_CONFIG);
273} 261}
274 262
275
276/* 263/*
277 * pl08x_terminate_phy_chan() stops the channel, clears the FIFO and 264 * pl08x_terminate_phy_chan() stops the channel, clears the FIFO and
278 * clears any pending interrupt status. This should not be used for 265 * clears any pending interrupt status. This should not be used for
@@ -407,6 +394,7 @@ pl08x_get_phy_channel(struct pl08x_driver_data *pl08x,
407 return NULL; 394 return NULL;
408 } 395 }
409 396
397 pm_runtime_get_sync(&pl08x->adev->dev);
410 return ch; 398 return ch;
411} 399}
412 400
@@ -420,6 +408,8 @@ static inline void pl08x_put_phy_channel(struct pl08x_driver_data *pl08x,
420 /* Stop the channel and clear its interrupts */ 408 /* Stop the channel and clear its interrupts */
421 pl08x_terminate_phy_chan(pl08x, ch); 409 pl08x_terminate_phy_chan(pl08x, ch);
422 410
411 pm_runtime_put(&pl08x->adev->dev);
412
423 /* Mark it as free */ 413 /* Mark it as free */
424 ch->serving = NULL; 414 ch->serving = NULL;
425 spin_unlock_irqrestore(&ch->lock, flags); 415 spin_unlock_irqrestore(&ch->lock, flags);
@@ -499,36 +489,30 @@ struct pl08x_lli_build_data {
499}; 489};
500 490
501/* 491/*
502 * Autoselect a master bus to use for the transfer this prefers the 492 * Autoselect a master bus to use for the transfer. Slave will be the chosen as
503 * destination bus if both available if fixed address on one bus the 493 * victim in case src & dest are not similarly aligned. i.e. If after aligning
504 * other will be chosen 494 * masters address with width requirements of transfer (by sending few byte by
495 * byte data), slave is still not aligned, then its width will be reduced to
496 * BYTE.
497 * - prefers the destination bus if both available
498 * - prefers bus with fixed address (i.e. peripheral)
505 */ 499 */
506static void pl08x_choose_master_bus(struct pl08x_lli_build_data *bd, 500static void pl08x_choose_master_bus(struct pl08x_lli_build_data *bd,
507 struct pl08x_bus_data **mbus, struct pl08x_bus_data **sbus, u32 cctl) 501 struct pl08x_bus_data **mbus, struct pl08x_bus_data **sbus, u32 cctl)
508{ 502{
509 if (!(cctl & PL080_CONTROL_DST_INCR)) { 503 if (!(cctl & PL080_CONTROL_DST_INCR)) {
510 *mbus = &bd->srcbus;
511 *sbus = &bd->dstbus;
512 } else if (!(cctl & PL080_CONTROL_SRC_INCR)) {
513 *mbus = &bd->dstbus; 504 *mbus = &bd->dstbus;
514 *sbus = &bd->srcbus; 505 *sbus = &bd->srcbus;
506 } else if (!(cctl & PL080_CONTROL_SRC_INCR)) {
507 *mbus = &bd->srcbus;
508 *sbus = &bd->dstbus;
515 } else { 509 } else {
516 if (bd->dstbus.buswidth == 4) { 510 if (bd->dstbus.buswidth >= bd->srcbus.buswidth) {
517 *mbus = &bd->dstbus; 511 *mbus = &bd->dstbus;
518 *sbus = &bd->srcbus; 512 *sbus = &bd->srcbus;
519 } else if (bd->srcbus.buswidth == 4) { 513 } else {
520 *mbus = &bd->srcbus;
521 *sbus = &bd->dstbus;
522 } else if (bd->dstbus.buswidth == 2) {
523 *mbus = &bd->dstbus;
524 *sbus = &bd->srcbus;
525 } else if (bd->srcbus.buswidth == 2) {
526 *mbus = &bd->srcbus; 514 *mbus = &bd->srcbus;
527 *sbus = &bd->dstbus; 515 *sbus = &bd->dstbus;
528 } else {
529 /* bd->srcbus.buswidth == 1 */
530 *mbus = &bd->dstbus;
531 *sbus = &bd->srcbus;
532 } 516 }
533 } 517 }
534} 518}
@@ -547,7 +531,8 @@ static void pl08x_fill_lli_for_desc(struct pl08x_lli_build_data *bd,
547 llis_va[num_llis].cctl = cctl; 531 llis_va[num_llis].cctl = cctl;
548 llis_va[num_llis].src = bd->srcbus.addr; 532 llis_va[num_llis].src = bd->srcbus.addr;
549 llis_va[num_llis].dst = bd->dstbus.addr; 533 llis_va[num_llis].dst = bd->dstbus.addr;
550 llis_va[num_llis].lli = llis_bus + (num_llis + 1) * sizeof(struct pl08x_lli); 534 llis_va[num_llis].lli = llis_bus + (num_llis + 1) *
535 sizeof(struct pl08x_lli);
551 llis_va[num_llis].lli |= bd->lli_bus; 536 llis_va[num_llis].lli |= bd->lli_bus;
552 537
553 if (cctl & PL080_CONTROL_SRC_INCR) 538 if (cctl & PL080_CONTROL_SRC_INCR)
@@ -560,16 +545,12 @@ static void pl08x_fill_lli_for_desc(struct pl08x_lli_build_data *bd,
560 bd->remainder -= len; 545 bd->remainder -= len;
561} 546}
562 547
563/* 548static inline void prep_byte_width_lli(struct pl08x_lli_build_data *bd,
564 * Return number of bytes to fill to boundary, or len. 549 u32 *cctl, u32 len, int num_llis, size_t *total_bytes)
565 * This calculation works for any value of addr.
566 */
567static inline size_t pl08x_pre_boundary(u32 addr, size_t len)
568{ 550{
569 size_t boundary_len = PL08X_BOUNDARY_SIZE - 551 *cctl = pl08x_cctl_bits(*cctl, 1, 1, len);
570 (addr & (PL08X_BOUNDARY_SIZE - 1)); 552 pl08x_fill_lli_for_desc(bd, num_llis, len, *cctl);
571 553 (*total_bytes) += len;
572 return min(boundary_len, len);
573} 554}
574 555
575/* 556/*
@@ -583,13 +564,11 @@ static int pl08x_fill_llis_for_desc(struct pl08x_driver_data *pl08x,
583 struct pl08x_bus_data *mbus, *sbus; 564 struct pl08x_bus_data *mbus, *sbus;
584 struct pl08x_lli_build_data bd; 565 struct pl08x_lli_build_data bd;
585 int num_llis = 0; 566 int num_llis = 0;
586 u32 cctl; 567 u32 cctl, early_bytes = 0;
587 size_t max_bytes_per_lli; 568 size_t max_bytes_per_lli, total_bytes = 0;
588 size_t total_bytes = 0;
589 struct pl08x_lli *llis_va; 569 struct pl08x_lli *llis_va;
590 570
591 txd->llis_va = dma_pool_alloc(pl08x->pool, GFP_NOWAIT, 571 txd->llis_va = dma_pool_alloc(pl08x->pool, GFP_NOWAIT, &txd->llis_bus);
592 &txd->llis_bus);
593 if (!txd->llis_va) { 572 if (!txd->llis_va) {
594 dev_err(&pl08x->adev->dev, "%s no memory for llis\n", __func__); 573 dev_err(&pl08x->adev->dev, "%s no memory for llis\n", __func__);
595 return 0; 574 return 0;
@@ -619,55 +598,85 @@ static int pl08x_fill_llis_for_desc(struct pl08x_driver_data *pl08x,
619 bd.srcbus.buswidth = bd.srcbus.maxwidth; 598 bd.srcbus.buswidth = bd.srcbus.maxwidth;
620 bd.dstbus.buswidth = bd.dstbus.maxwidth; 599 bd.dstbus.buswidth = bd.dstbus.maxwidth;
621 600
622 /*
623 * Bytes transferred == tsize * MIN(buswidths), not max(buswidths)
624 */
625 max_bytes_per_lli = min(bd.srcbus.buswidth, bd.dstbus.buswidth) *
626 PL080_CONTROL_TRANSFER_SIZE_MASK;
627
628 /* We need to count this down to zero */ 601 /* We need to count this down to zero */
629 bd.remainder = txd->len; 602 bd.remainder = txd->len;
630 603
631 /*
632 * Choose bus to align to
633 * - prefers destination bus if both available
634 * - if fixed address on one bus chooses other
635 */
636 pl08x_choose_master_bus(&bd, &mbus, &sbus, cctl); 604 pl08x_choose_master_bus(&bd, &mbus, &sbus, cctl);
637 605
638 dev_vdbg(&pl08x->adev->dev, "src=0x%08x%s/%u dst=0x%08x%s/%u len=%zu llimax=%zu\n", 606 dev_vdbg(&pl08x->adev->dev, "src=0x%08x%s/%u dst=0x%08x%s/%u len=%zu\n",
639 bd.srcbus.addr, cctl & PL080_CONTROL_SRC_INCR ? "+" : "", 607 bd.srcbus.addr, cctl & PL080_CONTROL_SRC_INCR ? "+" : "",
640 bd.srcbus.buswidth, 608 bd.srcbus.buswidth,
641 bd.dstbus.addr, cctl & PL080_CONTROL_DST_INCR ? "+" : "", 609 bd.dstbus.addr, cctl & PL080_CONTROL_DST_INCR ? "+" : "",
642 bd.dstbus.buswidth, 610 bd.dstbus.buswidth,
643 bd.remainder, max_bytes_per_lli); 611 bd.remainder);
644 dev_vdbg(&pl08x->adev->dev, "mbus=%s sbus=%s\n", 612 dev_vdbg(&pl08x->adev->dev, "mbus=%s sbus=%s\n",
645 mbus == &bd.srcbus ? "src" : "dst", 613 mbus == &bd.srcbus ? "src" : "dst",
646 sbus == &bd.srcbus ? "src" : "dst"); 614 sbus == &bd.srcbus ? "src" : "dst");
647 615
648 if (txd->len < mbus->buswidth) { 616 /*
649 /* Less than a bus width available - send as single bytes */ 617 * Zero length is only allowed if all these requirements are met:
650 while (bd.remainder) { 618 * - flow controller is peripheral.
651 dev_vdbg(&pl08x->adev->dev, 619 * - src.addr is aligned to src.width
652 "%s single byte LLIs for a transfer of " 620 * - dst.addr is aligned to dst.width
653 "less than a bus width (remain 0x%08x)\n", 621 *
654 __func__, bd.remainder); 622 * sg_len == 1 should be true, as there can be two cases here:
655 cctl = pl08x_cctl_bits(cctl, 1, 1, 1); 623 * - Memory addresses are contiguous and are not scattered. Here, Only
656 pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl); 624 * one sg will be passed by user driver, with memory address and zero
657 total_bytes++; 625 * length. We pass this to controller and after the transfer it will
626 * receive the last burst request from peripheral and so transfer
627 * finishes.
628 *
629 * - Memory addresses are scattered and are not contiguous. Here,
630 * Obviously as DMA controller doesn't know when a lli's transfer gets
631 * over, it can't load next lli. So in this case, there has to be an
632 * assumption that only one lli is supported. Thus, we can't have
633 * scattered addresses.
634 */
635 if (!bd.remainder) {
636 u32 fc = (txd->ccfg & PL080_CONFIG_FLOW_CONTROL_MASK) >>
637 PL080_CONFIG_FLOW_CONTROL_SHIFT;
638 if (!((fc >= PL080_FLOW_SRC2DST_DST) &&
639 (fc <= PL080_FLOW_SRC2DST_SRC))) {
640 dev_err(&pl08x->adev->dev, "%s sg len can't be zero",
641 __func__);
642 return 0;
658 } 643 }
659 } else { 644
660 /* Make one byte LLIs until master bus is aligned */ 645 if ((bd.srcbus.addr % bd.srcbus.buswidth) ||
661 while ((mbus->addr) % (mbus->buswidth)) { 646 (bd.srcbus.addr % bd.srcbus.buswidth)) {
662 dev_vdbg(&pl08x->adev->dev, 647 dev_err(&pl08x->adev->dev,
663 "%s adjustment lli for less than bus width " 648 "%s src & dst address must be aligned to src"
664 "(remain 0x%08x)\n", 649 " & dst width if peripheral is flow controller",
665 __func__, bd.remainder); 650 __func__);
666 cctl = pl08x_cctl_bits(cctl, 1, 1, 1); 651 return 0;
667 pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl);
668 total_bytes++;
669 } 652 }
670 653
654 cctl = pl08x_cctl_bits(cctl, bd.srcbus.buswidth,
655 bd.dstbus.buswidth, 0);
656 pl08x_fill_lli_for_desc(&bd, num_llis++, 0, cctl);
657 }
658
659 /*
660 * Send byte by byte for following cases
661 * - Less than a bus width available
662 * - until master bus is aligned
663 */
664 if (bd.remainder < mbus->buswidth)
665 early_bytes = bd.remainder;
666 else if ((mbus->addr) % (mbus->buswidth)) {
667 early_bytes = mbus->buswidth - (mbus->addr) % (mbus->buswidth);
668 if ((bd.remainder - early_bytes) < mbus->buswidth)
669 early_bytes = bd.remainder;
670 }
671
672 if (early_bytes) {
673 dev_vdbg(&pl08x->adev->dev, "%s byte width LLIs "
674 "(remain 0x%08x)\n", __func__, bd.remainder);
675 prep_byte_width_lli(&bd, &cctl, early_bytes, num_llis++,
676 &total_bytes);
677 }
678
679 if (bd.remainder) {
671 /* 680 /*
672 * Master now aligned 681 * Master now aligned
673 * - if slave is not then we must set its width down 682 * - if slave is not then we must set its width down
@@ -680,138 +689,55 @@ static int pl08x_fill_llis_for_desc(struct pl08x_driver_data *pl08x,
680 sbus->buswidth = 1; 689 sbus->buswidth = 1;
681 } 690 }
682 691
692 /* Bytes transferred = tsize * src width, not MIN(buswidths) */
693 max_bytes_per_lli = bd.srcbus.buswidth *
694 PL080_CONTROL_TRANSFER_SIZE_MASK;
695
683 /* 696 /*
684 * Make largest possible LLIs until less than one bus 697 * Make largest possible LLIs until less than one bus
685 * width left 698 * width left
686 */ 699 */
687 while (bd.remainder > (mbus->buswidth - 1)) { 700 while (bd.remainder > (mbus->buswidth - 1)) {
688 size_t lli_len, target_len, tsize, odd_bytes; 701 size_t lli_len, tsize, width;
689 702
690 /* 703 /*
691 * If enough left try to send max possible, 704 * If enough left try to send max possible,
692 * otherwise try to send the remainder 705 * otherwise try to send the remainder
693 */ 706 */
694 target_len = min(bd.remainder, max_bytes_per_lli); 707 lli_len = min(bd.remainder, max_bytes_per_lli);
695 708
696 /* 709 /*
697 * Set bus lengths for incrementing buses to the 710 * Check against maximum bus alignment: Calculate actual
698 * number of bytes which fill to next memory boundary, 711 * transfer size in relation to bus width and get a
699 * limiting on the target length calculated above. 712 * maximum remainder of the highest bus width - 1
700 */ 713 */
701 if (cctl & PL080_CONTROL_SRC_INCR) 714 width = max(mbus->buswidth, sbus->buswidth);
702 bd.srcbus.fill_bytes = 715 lli_len = (lli_len / width) * width;
703 pl08x_pre_boundary(bd.srcbus.addr, 716 tsize = lli_len / bd.srcbus.buswidth;
704 target_len);
705 else
706 bd.srcbus.fill_bytes = target_len;
707
708 if (cctl & PL080_CONTROL_DST_INCR)
709 bd.dstbus.fill_bytes =
710 pl08x_pre_boundary(bd.dstbus.addr,
711 target_len);
712 else
713 bd.dstbus.fill_bytes = target_len;
714
715 /* Find the nearest */
716 lli_len = min(bd.srcbus.fill_bytes,
717 bd.dstbus.fill_bytes);
718
719 BUG_ON(lli_len > bd.remainder);
720
721 if (lli_len <= 0) {
722 dev_err(&pl08x->adev->dev,
723 "%s lli_len is %zu, <= 0\n",
724 __func__, lli_len);
725 return 0;
726 }
727 717
728 if (lli_len == target_len) { 718 dev_vdbg(&pl08x->adev->dev,
729 /* 719 "%s fill lli with single lli chunk of "
730 * Can send what we wanted. 720 "size 0x%08zx (remainder 0x%08zx)\n",
731 * Maintain alignment 721 __func__, lli_len, bd.remainder);
732 */ 722
733 lli_len = (lli_len/mbus->buswidth) * 723 cctl = pl08x_cctl_bits(cctl, bd.srcbus.buswidth,
734 mbus->buswidth; 724 bd.dstbus.buswidth, tsize);
735 odd_bytes = 0; 725 pl08x_fill_lli_for_desc(&bd, num_llis++, lli_len, cctl);
736 } else { 726 total_bytes += lli_len;
737 /*
738 * So now we know how many bytes to transfer
739 * to get to the nearest boundary. The next
740 * LLI will past the boundary. However, we
741 * may be working to a boundary on the slave
742 * bus. We need to ensure the master stays
743 * aligned, and that we are working in
744 * multiples of the bus widths.
745 */
746 odd_bytes = lli_len % mbus->buswidth;
747 lli_len -= odd_bytes;
748
749 }
750
751 if (lli_len) {
752 /*
753 * Check against minimum bus alignment:
754 * Calculate actual transfer size in relation
755 * to bus width an get a maximum remainder of
756 * the smallest bus width - 1
757 */
758 /* FIXME: use round_down()? */
759 tsize = lli_len / min(mbus->buswidth,
760 sbus->buswidth);
761 lli_len = tsize * min(mbus->buswidth,
762 sbus->buswidth);
763
764 if (target_len != lli_len) {
765 dev_vdbg(&pl08x->adev->dev,
766 "%s can't send what we want. Desired 0x%08zx, lli of 0x%08zx bytes in txd of 0x%08zx\n",
767 __func__, target_len, lli_len, txd->len);
768 }
769
770 cctl = pl08x_cctl_bits(cctl,
771 bd.srcbus.buswidth,
772 bd.dstbus.buswidth,
773 tsize);
774
775 dev_vdbg(&pl08x->adev->dev,
776 "%s fill lli with single lli chunk of size 0x%08zx (remainder 0x%08zx)\n",
777 __func__, lli_len, bd.remainder);
778 pl08x_fill_lli_for_desc(&bd, num_llis++,
779 lli_len, cctl);
780 total_bytes += lli_len;
781 }
782
783
784 if (odd_bytes) {
785 /*
786 * Creep past the boundary, maintaining
787 * master alignment
788 */
789 int j;
790 for (j = 0; (j < mbus->buswidth)
791 && (bd.remainder); j++) {
792 cctl = pl08x_cctl_bits(cctl, 1, 1, 1);
793 dev_vdbg(&pl08x->adev->dev,
794 "%s align with boundary, single byte (remain 0x%08zx)\n",
795 __func__, bd.remainder);
796 pl08x_fill_lli_for_desc(&bd,
797 num_llis++, 1, cctl);
798 total_bytes++;
799 }
800 }
801 } 727 }
802 728
803 /* 729 /*
804 * Send any odd bytes 730 * Send any odd bytes
805 */ 731 */
806 while (bd.remainder) { 732 if (bd.remainder) {
807 cctl = pl08x_cctl_bits(cctl, 1, 1, 1);
808 dev_vdbg(&pl08x->adev->dev, 733 dev_vdbg(&pl08x->adev->dev,
809 "%s align with boundary, single odd byte (remain %zu)\n", 734 "%s align with boundary, send odd bytes (remain %zu)\n",
810 __func__, bd.remainder); 735 __func__, bd.remainder);
811 pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl); 736 prep_byte_width_lli(&bd, &cctl, bd.remainder,
812 total_bytes++; 737 num_llis++, &total_bytes);
813 } 738 }
814 } 739 }
740
815 if (total_bytes != txd->len) { 741 if (total_bytes != txd->len) {
816 dev_err(&pl08x->adev->dev, 742 dev_err(&pl08x->adev->dev,
817 "%s size of encoded lli:s don't match total txd, transferred 0x%08zx from size 0x%08zx\n", 743 "%s size of encoded lli:s don't match total txd, transferred 0x%08zx from size 0x%08zx\n",
@@ -917,9 +843,7 @@ static int prep_phy_channel(struct pl08x_dma_chan *plchan,
917 * need, but for slaves the physical signals may be muxed! 843 * need, but for slaves the physical signals may be muxed!
918 * Can the platform allow us to use this channel? 844 * Can the platform allow us to use this channel?
919 */ 845 */
920 if (plchan->slave && 846 if (plchan->slave && pl08x->pd->get_signal) {
921 ch->signal < 0 &&
922 pl08x->pd->get_signal) {
923 ret = pl08x->pd->get_signal(plchan); 847 ret = pl08x->pd->get_signal(plchan);
924 if (ret < 0) { 848 if (ret < 0) {
925 dev_dbg(&pl08x->adev->dev, 849 dev_dbg(&pl08x->adev->dev,
@@ -1008,10 +932,8 @@ static struct dma_async_tx_descriptor *pl08x_prep_dma_interrupt(
1008 * If slaves are relying on interrupts to signal completion this function 932 * If slaves are relying on interrupts to signal completion this function
1009 * must not be called with interrupts disabled. 933 * must not be called with interrupts disabled.
1010 */ 934 */
1011static enum dma_status 935static enum dma_status pl08x_dma_tx_status(struct dma_chan *chan,
1012pl08x_dma_tx_status(struct dma_chan *chan, 936 dma_cookie_t cookie, struct dma_tx_state *txstate)
1013 dma_cookie_t cookie,
1014 struct dma_tx_state *txstate)
1015{ 937{
1016 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 938 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
1017 dma_cookie_t last_used; 939 dma_cookie_t last_used;
@@ -1253,7 +1175,9 @@ static int pl08x_prep_channel_resources(struct pl08x_dma_chan *plchan,
1253 1175
1254 num_llis = pl08x_fill_llis_for_desc(pl08x, txd); 1176 num_llis = pl08x_fill_llis_for_desc(pl08x, txd);
1255 if (!num_llis) { 1177 if (!num_llis) {
1256 kfree(txd); 1178 spin_lock_irqsave(&plchan->lock, flags);
1179 pl08x_free_txd(pl08x, txd);
1180 spin_unlock_irqrestore(&plchan->lock, flags);
1257 return -EINVAL; 1181 return -EINVAL;
1258 } 1182 }
1259 1183
@@ -1301,7 +1225,7 @@ static int pl08x_prep_channel_resources(struct pl08x_dma_chan *plchan,
1301static struct pl08x_txd *pl08x_get_txd(struct pl08x_dma_chan *plchan, 1225static struct pl08x_txd *pl08x_get_txd(struct pl08x_dma_chan *plchan,
1302 unsigned long flags) 1226 unsigned long flags)
1303{ 1227{
1304 struct pl08x_txd *txd = kzalloc(sizeof(struct pl08x_txd), GFP_NOWAIT); 1228 struct pl08x_txd *txd = kzalloc(sizeof(*txd), GFP_NOWAIT);
1305 1229
1306 if (txd) { 1230 if (txd) {
1307 dma_async_tx_descriptor_init(&txd->tx, &plchan->chan); 1231 dma_async_tx_descriptor_init(&txd->tx, &plchan->chan);
@@ -1367,7 +1291,7 @@ static struct dma_async_tx_descriptor *pl08x_prep_slave_sg(
1367 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 1291 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
1368 struct pl08x_driver_data *pl08x = plchan->host; 1292 struct pl08x_driver_data *pl08x = plchan->host;
1369 struct pl08x_txd *txd; 1293 struct pl08x_txd *txd;
1370 int ret; 1294 int ret, tmp;
1371 1295
1372 /* 1296 /*
1373 * Current implementation ASSUMES only one sg 1297 * Current implementation ASSUMES only one sg
@@ -1401,12 +1325,10 @@ static struct dma_async_tx_descriptor *pl08x_prep_slave_sg(
1401 txd->len = sgl->length; 1325 txd->len = sgl->length;
1402 1326
1403 if (direction == DMA_TO_DEVICE) { 1327 if (direction == DMA_TO_DEVICE) {
1404 txd->ccfg |= PL080_FLOW_MEM2PER << PL080_CONFIG_FLOW_CONTROL_SHIFT;
1405 txd->cctl = plchan->dst_cctl; 1328 txd->cctl = plchan->dst_cctl;
1406 txd->src_addr = sgl->dma_address; 1329 txd->src_addr = sgl->dma_address;
1407 txd->dst_addr = plchan->dst_addr; 1330 txd->dst_addr = plchan->dst_addr;
1408 } else if (direction == DMA_FROM_DEVICE) { 1331 } else if (direction == DMA_FROM_DEVICE) {
1409 txd->ccfg |= PL080_FLOW_PER2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT;
1410 txd->cctl = plchan->src_cctl; 1332 txd->cctl = plchan->src_cctl;
1411 txd->src_addr = plchan->src_addr; 1333 txd->src_addr = plchan->src_addr;
1412 txd->dst_addr = sgl->dma_address; 1334 txd->dst_addr = sgl->dma_address;
@@ -1416,6 +1338,15 @@ static struct dma_async_tx_descriptor *pl08x_prep_slave_sg(
1416 return NULL; 1338 return NULL;
1417 } 1339 }
1418 1340
1341 if (plchan->cd->device_fc)
1342 tmp = (direction == DMA_TO_DEVICE) ? PL080_FLOW_MEM2PER_PER :
1343 PL080_FLOW_PER2MEM_PER;
1344 else
1345 tmp = (direction == DMA_TO_DEVICE) ? PL080_FLOW_MEM2PER :
1346 PL080_FLOW_PER2MEM;
1347
1348 txd->ccfg |= tmp << PL080_CONFIG_FLOW_CONTROL_SHIFT;
1349
1419 ret = pl08x_prep_channel_resources(plchan, txd); 1350 ret = pl08x_prep_channel_resources(plchan, txd);
1420 if (ret) 1351 if (ret)
1421 return NULL; 1352 return NULL;
@@ -1507,13 +1438,7 @@ bool pl08x_filter_id(struct dma_chan *chan, void *chan_id)
1507 */ 1438 */
1508static void pl08x_ensure_on(struct pl08x_driver_data *pl08x) 1439static void pl08x_ensure_on(struct pl08x_driver_data *pl08x)
1509{ 1440{
1510 u32 val; 1441 writel(PL080_CONFIG_ENABLE, pl08x->base + PL080_CONFIG);
1511
1512 val = readl(pl08x->base + PL080_CONFIG);
1513 val &= ~(PL080_CONFIG_M2_BE | PL080_CONFIG_M1_BE | PL080_CONFIG_ENABLE);
1514 /* We implicitly clear bit 1 and that means little-endian mode */
1515 val |= PL080_CONFIG_ENABLE;
1516 writel(val, pl08x->base + PL080_CONFIG);
1517} 1442}
1518 1443
1519static void pl08x_unmap_buffers(struct pl08x_txd *txd) 1444static void pl08x_unmap_buffers(struct pl08x_txd *txd)
@@ -1589,8 +1514,8 @@ static void pl08x_tasklet(unsigned long data)
1589 */ 1514 */
1590 list_for_each_entry(waiting, &pl08x->memcpy.channels, 1515 list_for_each_entry(waiting, &pl08x->memcpy.channels,
1591 chan.device_node) { 1516 chan.device_node) {
1592 if (waiting->state == PL08X_CHAN_WAITING && 1517 if (waiting->state == PL08X_CHAN_WAITING &&
1593 waiting->waiting != NULL) { 1518 waiting->waiting != NULL) {
1594 int ret; 1519 int ret;
1595 1520
1596 /* This should REALLY not fail now */ 1521 /* This should REALLY not fail now */
@@ -1630,38 +1555,40 @@ static void pl08x_tasklet(unsigned long data)
1630static irqreturn_t pl08x_irq(int irq, void *dev) 1555static irqreturn_t pl08x_irq(int irq, void *dev)
1631{ 1556{
1632 struct pl08x_driver_data *pl08x = dev; 1557 struct pl08x_driver_data *pl08x = dev;
1633 u32 mask = 0; 1558 u32 mask = 0, err, tc, i;
1634 u32 val; 1559
1635 int i; 1560 /* check & clear - ERR & TC interrupts */
1636 1561 err = readl(pl08x->base + PL080_ERR_STATUS);
1637 val = readl(pl08x->base + PL080_ERR_STATUS); 1562 if (err) {
1638 if (val) { 1563 dev_err(&pl08x->adev->dev, "%s error interrupt, register value 0x%08x\n",
1639 /* An error interrupt (on one or more channels) */ 1564 __func__, err);
1640 dev_err(&pl08x->adev->dev, 1565 writel(err, pl08x->base + PL080_ERR_CLEAR);
1641 "%s error interrupt, register value 0x%08x\n",
1642 __func__, val);
1643 /*
1644 * Simply clear ALL PL08X error interrupts,
1645 * regardless of channel and cause
1646 * FIXME: should be 0x00000003 on PL081 really.
1647 */
1648 writel(0x000000FF, pl08x->base + PL080_ERR_CLEAR);
1649 } 1566 }
1650 val = readl(pl08x->base + PL080_INT_STATUS); 1567 tc = readl(pl08x->base + PL080_INT_STATUS);
1568 if (tc)
1569 writel(tc, pl08x->base + PL080_TC_CLEAR);
1570
1571 if (!err && !tc)
1572 return IRQ_NONE;
1573
1651 for (i = 0; i < pl08x->vd->channels; i++) { 1574 for (i = 0; i < pl08x->vd->channels; i++) {
1652 if ((1 << i) & val) { 1575 if (((1 << i) & err) || ((1 << i) & tc)) {
1653 /* Locate physical channel */ 1576 /* Locate physical channel */
1654 struct pl08x_phy_chan *phychan = &pl08x->phy_chans[i]; 1577 struct pl08x_phy_chan *phychan = &pl08x->phy_chans[i];
1655 struct pl08x_dma_chan *plchan = phychan->serving; 1578 struct pl08x_dma_chan *plchan = phychan->serving;
1656 1579
1580 if (!plchan) {
1581 dev_err(&pl08x->adev->dev,
1582 "%s Error TC interrupt on unused channel: 0x%08x\n",
1583 __func__, i);
1584 continue;
1585 }
1586
1657 /* Schedule tasklet on this channel */ 1587 /* Schedule tasklet on this channel */
1658 tasklet_schedule(&plchan->tasklet); 1588 tasklet_schedule(&plchan->tasklet);
1659
1660 mask |= (1 << i); 1589 mask |= (1 << i);
1661 } 1590 }
1662 } 1591 }
1663 /* Clear only the terminal interrupts on channels we processed */
1664 writel(mask, pl08x->base + PL080_TC_CLEAR);
1665 1592
1666 return mask ? IRQ_HANDLED : IRQ_NONE; 1593 return mask ? IRQ_HANDLED : IRQ_NONE;
1667} 1594}
@@ -1685,9 +1612,7 @@ static void pl08x_dma_slave_init(struct pl08x_dma_chan *chan)
1685 * Make a local wrapper to hold required data 1612 * Make a local wrapper to hold required data
1686 */ 1613 */
1687static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x, 1614static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x,
1688 struct dma_device *dmadev, 1615 struct dma_device *dmadev, unsigned int channels, bool slave)
1689 unsigned int channels,
1690 bool slave)
1691{ 1616{
1692 struct pl08x_dma_chan *chan; 1617 struct pl08x_dma_chan *chan;
1693 int i; 1618 int i;
@@ -1700,7 +1625,7 @@ static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x,
1700 * to cope with that situation. 1625 * to cope with that situation.
1701 */ 1626 */
1702 for (i = 0; i < channels; i++) { 1627 for (i = 0; i < channels; i++) {
1703 chan = kzalloc(sizeof(struct pl08x_dma_chan), GFP_KERNEL); 1628 chan = kzalloc(sizeof(*chan), GFP_KERNEL);
1704 if (!chan) { 1629 if (!chan) {
1705 dev_err(&pl08x->adev->dev, 1630 dev_err(&pl08x->adev->dev,
1706 "%s no memory for channel\n", __func__); 1631 "%s no memory for channel\n", __func__);
@@ -1728,7 +1653,7 @@ static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x,
1728 kfree(chan); 1653 kfree(chan);
1729 continue; 1654 continue;
1730 } 1655 }
1731 dev_info(&pl08x->adev->dev, 1656 dev_dbg(&pl08x->adev->dev,
1732 "initialize virtual channel \"%s\"\n", 1657 "initialize virtual channel \"%s\"\n",
1733 chan->name); 1658 chan->name);
1734 1659
@@ -1837,9 +1762,9 @@ static const struct file_operations pl08x_debugfs_operations = {
1837static void init_pl08x_debugfs(struct pl08x_driver_data *pl08x) 1762static void init_pl08x_debugfs(struct pl08x_driver_data *pl08x)
1838{ 1763{
1839 /* Expose a simple debugfs interface to view all clocks */ 1764 /* Expose a simple debugfs interface to view all clocks */
1840 (void) debugfs_create_file(dev_name(&pl08x->adev->dev), S_IFREG | S_IRUGO, 1765 (void) debugfs_create_file(dev_name(&pl08x->adev->dev),
1841 NULL, pl08x, 1766 S_IFREG | S_IRUGO, NULL, pl08x,
1842 &pl08x_debugfs_operations); 1767 &pl08x_debugfs_operations);
1843} 1768}
1844 1769
1845#else 1770#else
@@ -1860,12 +1785,15 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
1860 return ret; 1785 return ret;
1861 1786
1862 /* Create the driver state holder */ 1787 /* Create the driver state holder */
1863 pl08x = kzalloc(sizeof(struct pl08x_driver_data), GFP_KERNEL); 1788 pl08x = kzalloc(sizeof(*pl08x), GFP_KERNEL);
1864 if (!pl08x) { 1789 if (!pl08x) {
1865 ret = -ENOMEM; 1790 ret = -ENOMEM;
1866 goto out_no_pl08x; 1791 goto out_no_pl08x;
1867 } 1792 }
1868 1793
1794 pm_runtime_set_active(&adev->dev);
1795 pm_runtime_enable(&adev->dev);
1796
1869 /* Initialize memcpy engine */ 1797 /* Initialize memcpy engine */
1870 dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask); 1798 dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask);
1871 pl08x->memcpy.dev = &adev->dev; 1799 pl08x->memcpy.dev = &adev->dev;
@@ -1939,7 +1867,7 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
1939 } 1867 }
1940 1868
1941 /* Initialize physical channels */ 1869 /* Initialize physical channels */
1942 pl08x->phy_chans = kmalloc((vd->channels * sizeof(struct pl08x_phy_chan)), 1870 pl08x->phy_chans = kmalloc((vd->channels * sizeof(*pl08x->phy_chans)),
1943 GFP_KERNEL); 1871 GFP_KERNEL);
1944 if (!pl08x->phy_chans) { 1872 if (!pl08x->phy_chans) {
1945 dev_err(&adev->dev, "%s failed to allocate " 1873 dev_err(&adev->dev, "%s failed to allocate "
@@ -1956,9 +1884,8 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
1956 spin_lock_init(&ch->lock); 1884 spin_lock_init(&ch->lock);
1957 ch->serving = NULL; 1885 ch->serving = NULL;
1958 ch->signal = -1; 1886 ch->signal = -1;
1959 dev_info(&adev->dev, 1887 dev_dbg(&adev->dev, "physical channel %d is %s\n",
1960 "physical channel %d is %s\n", i, 1888 i, pl08x_phy_channel_busy(ch) ? "BUSY" : "FREE");
1961 pl08x_phy_channel_busy(ch) ? "BUSY" : "FREE");
1962 } 1889 }
1963 1890
1964 /* Register as many memcpy channels as there are physical channels */ 1891 /* Register as many memcpy channels as there are physical channels */
@@ -1974,8 +1901,7 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
1974 1901
1975 /* Register slave channels */ 1902 /* Register slave channels */
1976 ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->slave, 1903 ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->slave,
1977 pl08x->pd->num_slave_channels, 1904 pl08x->pd->num_slave_channels, true);
1978 true);
1979 if (ret <= 0) { 1905 if (ret <= 0) {
1980 dev_warn(&pl08x->adev->dev, 1906 dev_warn(&pl08x->adev->dev,
1981 "%s failed to enumerate slave channels - %d\n", 1907 "%s failed to enumerate slave channels - %d\n",
@@ -2005,6 +1931,8 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
2005 dev_info(&pl08x->adev->dev, "DMA: PL%03x rev%u at 0x%08llx irq %d\n", 1931 dev_info(&pl08x->adev->dev, "DMA: PL%03x rev%u at 0x%08llx irq %d\n",
2006 amba_part(adev), amba_rev(adev), 1932 amba_part(adev), amba_rev(adev),
2007 (unsigned long long)adev->res.start, adev->irq[0]); 1933 (unsigned long long)adev->res.start, adev->irq[0]);
1934
1935 pm_runtime_put(&adev->dev);
2008 return 0; 1936 return 0;
2009 1937
2010out_no_slave_reg: 1938out_no_slave_reg:
@@ -2023,6 +1951,9 @@ out_no_ioremap:
2023 dma_pool_destroy(pl08x->pool); 1951 dma_pool_destroy(pl08x->pool);
2024out_no_lli_pool: 1952out_no_lli_pool:
2025out_no_platdata: 1953out_no_platdata:
1954 pm_runtime_put(&adev->dev);
1955 pm_runtime_disable(&adev->dev);
1956
2026 kfree(pl08x); 1957 kfree(pl08x);
2027out_no_pl08x: 1958out_no_pl08x:
2028 amba_release_regions(adev); 1959 amba_release_regions(adev);
diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index 6a483eac7b3f..3b99dc62874b 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -107,10 +107,11 @@ static struct at_desc *atc_desc_get(struct at_dma_chan *atchan)
107{ 107{
108 struct at_desc *desc, *_desc; 108 struct at_desc *desc, *_desc;
109 struct at_desc *ret = NULL; 109 struct at_desc *ret = NULL;
110 unsigned long flags;
110 unsigned int i = 0; 111 unsigned int i = 0;
111 LIST_HEAD(tmp_list); 112 LIST_HEAD(tmp_list);
112 113
113 spin_lock_bh(&atchan->lock); 114 spin_lock_irqsave(&atchan->lock, flags);
114 list_for_each_entry_safe(desc, _desc, &atchan->free_list, desc_node) { 115 list_for_each_entry_safe(desc, _desc, &atchan->free_list, desc_node) {
115 i++; 116 i++;
116 if (async_tx_test_ack(&desc->txd)) { 117 if (async_tx_test_ack(&desc->txd)) {
@@ -121,7 +122,7 @@ static struct at_desc *atc_desc_get(struct at_dma_chan *atchan)
121 dev_dbg(chan2dev(&atchan->chan_common), 122 dev_dbg(chan2dev(&atchan->chan_common),
122 "desc %p not ACKed\n", desc); 123 "desc %p not ACKed\n", desc);
123 } 124 }
124 spin_unlock_bh(&atchan->lock); 125 spin_unlock_irqrestore(&atchan->lock, flags);
125 dev_vdbg(chan2dev(&atchan->chan_common), 126 dev_vdbg(chan2dev(&atchan->chan_common),
126 "scanned %u descriptors on freelist\n", i); 127 "scanned %u descriptors on freelist\n", i);
127 128
@@ -129,9 +130,9 @@ static struct at_desc *atc_desc_get(struct at_dma_chan *atchan)
129 if (!ret) { 130 if (!ret) {
130 ret = atc_alloc_descriptor(&atchan->chan_common, GFP_ATOMIC); 131 ret = atc_alloc_descriptor(&atchan->chan_common, GFP_ATOMIC);
131 if (ret) { 132 if (ret) {
132 spin_lock_bh(&atchan->lock); 133 spin_lock_irqsave(&atchan->lock, flags);
133 atchan->descs_allocated++; 134 atchan->descs_allocated++;
134 spin_unlock_bh(&atchan->lock); 135 spin_unlock_irqrestore(&atchan->lock, flags);
135 } else { 136 } else {
136 dev_err(chan2dev(&atchan->chan_common), 137 dev_err(chan2dev(&atchan->chan_common),
137 "not enough descriptors available\n"); 138 "not enough descriptors available\n");
@@ -150,8 +151,9 @@ static void atc_desc_put(struct at_dma_chan *atchan, struct at_desc *desc)
150{ 151{
151 if (desc) { 152 if (desc) {
152 struct at_desc *child; 153 struct at_desc *child;
154 unsigned long flags;
153 155
154 spin_lock_bh(&atchan->lock); 156 spin_lock_irqsave(&atchan->lock, flags);
155 list_for_each_entry(child, &desc->tx_list, desc_node) 157 list_for_each_entry(child, &desc->tx_list, desc_node)
156 dev_vdbg(chan2dev(&atchan->chan_common), 158 dev_vdbg(chan2dev(&atchan->chan_common),
157 "moving child desc %p to freelist\n", 159 "moving child desc %p to freelist\n",
@@ -160,7 +162,7 @@ static void atc_desc_put(struct at_dma_chan *atchan, struct at_desc *desc)
160 dev_vdbg(chan2dev(&atchan->chan_common), 162 dev_vdbg(chan2dev(&atchan->chan_common),
161 "moving desc %p to freelist\n", desc); 163 "moving desc %p to freelist\n", desc);
162 list_add(&desc->desc_node, &atchan->free_list); 164 list_add(&desc->desc_node, &atchan->free_list);
163 spin_unlock_bh(&atchan->lock); 165 spin_unlock_irqrestore(&atchan->lock, flags);
164 } 166 }
165} 167}
166 168
@@ -299,7 +301,7 @@ atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc)
299 301
300 /* for cyclic transfers, 302 /* for cyclic transfers,
301 * no need to replay callback function while stopping */ 303 * no need to replay callback function while stopping */
302 if (!test_bit(ATC_IS_CYCLIC, &atchan->status)) { 304 if (!atc_chan_is_cyclic(atchan)) {
303 dma_async_tx_callback callback = txd->callback; 305 dma_async_tx_callback callback = txd->callback;
304 void *param = txd->callback_param; 306 void *param = txd->callback_param;
305 307
@@ -471,16 +473,17 @@ static void atc_handle_cyclic(struct at_dma_chan *atchan)
471static void atc_tasklet(unsigned long data) 473static void atc_tasklet(unsigned long data)
472{ 474{
473 struct at_dma_chan *atchan = (struct at_dma_chan *)data; 475 struct at_dma_chan *atchan = (struct at_dma_chan *)data;
476 unsigned long flags;
474 477
475 spin_lock(&atchan->lock); 478 spin_lock_irqsave(&atchan->lock, flags);
476 if (test_and_clear_bit(ATC_IS_ERROR, &atchan->status)) 479 if (test_and_clear_bit(ATC_IS_ERROR, &atchan->status))
477 atc_handle_error(atchan); 480 atc_handle_error(atchan);
478 else if (test_bit(ATC_IS_CYCLIC, &atchan->status)) 481 else if (atc_chan_is_cyclic(atchan))
479 atc_handle_cyclic(atchan); 482 atc_handle_cyclic(atchan);
480 else 483 else
481 atc_advance_work(atchan); 484 atc_advance_work(atchan);
482 485
483 spin_unlock(&atchan->lock); 486 spin_unlock_irqrestore(&atchan->lock, flags);
484} 487}
485 488
486static irqreturn_t at_dma_interrupt(int irq, void *dev_id) 489static irqreturn_t at_dma_interrupt(int irq, void *dev_id)
@@ -539,8 +542,9 @@ static dma_cookie_t atc_tx_submit(struct dma_async_tx_descriptor *tx)
539 struct at_desc *desc = txd_to_at_desc(tx); 542 struct at_desc *desc = txd_to_at_desc(tx);
540 struct at_dma_chan *atchan = to_at_dma_chan(tx->chan); 543 struct at_dma_chan *atchan = to_at_dma_chan(tx->chan);
541 dma_cookie_t cookie; 544 dma_cookie_t cookie;
545 unsigned long flags;
542 546
543 spin_lock_bh(&atchan->lock); 547 spin_lock_irqsave(&atchan->lock, flags);
544 cookie = atc_assign_cookie(atchan, desc); 548 cookie = atc_assign_cookie(atchan, desc);
545 549
546 if (list_empty(&atchan->active_list)) { 550 if (list_empty(&atchan->active_list)) {
@@ -554,7 +558,7 @@ static dma_cookie_t atc_tx_submit(struct dma_async_tx_descriptor *tx)
554 list_add_tail(&desc->desc_node, &atchan->queue); 558 list_add_tail(&desc->desc_node, &atchan->queue);
555 } 559 }
556 560
557 spin_unlock_bh(&atchan->lock); 561 spin_unlock_irqrestore(&atchan->lock, flags);
558 562
559 return cookie; 563 return cookie;
560} 564}
@@ -927,28 +931,29 @@ static int atc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
927 struct at_dma_chan *atchan = to_at_dma_chan(chan); 931 struct at_dma_chan *atchan = to_at_dma_chan(chan);
928 struct at_dma *atdma = to_at_dma(chan->device); 932 struct at_dma *atdma = to_at_dma(chan->device);
929 int chan_id = atchan->chan_common.chan_id; 933 int chan_id = atchan->chan_common.chan_id;
934 unsigned long flags;
930 935
931 LIST_HEAD(list); 936 LIST_HEAD(list);
932 937
933 dev_vdbg(chan2dev(chan), "atc_control (%d)\n", cmd); 938 dev_vdbg(chan2dev(chan), "atc_control (%d)\n", cmd);
934 939
935 if (cmd == DMA_PAUSE) { 940 if (cmd == DMA_PAUSE) {
936 spin_lock_bh(&atchan->lock); 941 spin_lock_irqsave(&atchan->lock, flags);
937 942
938 dma_writel(atdma, CHER, AT_DMA_SUSP(chan_id)); 943 dma_writel(atdma, CHER, AT_DMA_SUSP(chan_id));
939 set_bit(ATC_IS_PAUSED, &atchan->status); 944 set_bit(ATC_IS_PAUSED, &atchan->status);
940 945
941 spin_unlock_bh(&atchan->lock); 946 spin_unlock_irqrestore(&atchan->lock, flags);
942 } else if (cmd == DMA_RESUME) { 947 } else if (cmd == DMA_RESUME) {
943 if (!test_bit(ATC_IS_PAUSED, &atchan->status)) 948 if (!atc_chan_is_paused(atchan))
944 return 0; 949 return 0;
945 950
946 spin_lock_bh(&atchan->lock); 951 spin_lock_irqsave(&atchan->lock, flags);
947 952
948 dma_writel(atdma, CHDR, AT_DMA_RES(chan_id)); 953 dma_writel(atdma, CHDR, AT_DMA_RES(chan_id));
949 clear_bit(ATC_IS_PAUSED, &atchan->status); 954 clear_bit(ATC_IS_PAUSED, &atchan->status);
950 955
951 spin_unlock_bh(&atchan->lock); 956 spin_unlock_irqrestore(&atchan->lock, flags);
952 } else if (cmd == DMA_TERMINATE_ALL) { 957 } else if (cmd == DMA_TERMINATE_ALL) {
953 struct at_desc *desc, *_desc; 958 struct at_desc *desc, *_desc;
954 /* 959 /*
@@ -957,7 +962,7 @@ static int atc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
957 * channel. We still have to poll the channel enable bit due 962 * channel. We still have to poll the channel enable bit due
958 * to AHB/HSB limitations. 963 * to AHB/HSB limitations.
959 */ 964 */
960 spin_lock_bh(&atchan->lock); 965 spin_lock_irqsave(&atchan->lock, flags);
961 966
962 /* disabling channel: must also remove suspend state */ 967 /* disabling channel: must also remove suspend state */
963 dma_writel(atdma, CHDR, AT_DMA_RES(chan_id) | atchan->mask); 968 dma_writel(atdma, CHDR, AT_DMA_RES(chan_id) | atchan->mask);
@@ -978,7 +983,7 @@ static int atc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
978 /* if channel dedicated to cyclic operations, free it */ 983 /* if channel dedicated to cyclic operations, free it */
979 clear_bit(ATC_IS_CYCLIC, &atchan->status); 984 clear_bit(ATC_IS_CYCLIC, &atchan->status);
980 985
981 spin_unlock_bh(&atchan->lock); 986 spin_unlock_irqrestore(&atchan->lock, flags);
982 } else { 987 } else {
983 return -ENXIO; 988 return -ENXIO;
984 } 989 }
@@ -1004,9 +1009,10 @@ atc_tx_status(struct dma_chan *chan,
1004 struct at_dma_chan *atchan = to_at_dma_chan(chan); 1009 struct at_dma_chan *atchan = to_at_dma_chan(chan);
1005 dma_cookie_t last_used; 1010 dma_cookie_t last_used;
1006 dma_cookie_t last_complete; 1011 dma_cookie_t last_complete;
1012 unsigned long flags;
1007 enum dma_status ret; 1013 enum dma_status ret;
1008 1014
1009 spin_lock_bh(&atchan->lock); 1015 spin_lock_irqsave(&atchan->lock, flags);
1010 1016
1011 last_complete = atchan->completed_cookie; 1017 last_complete = atchan->completed_cookie;
1012 last_used = chan->cookie; 1018 last_used = chan->cookie;
@@ -1021,7 +1027,7 @@ atc_tx_status(struct dma_chan *chan,
1021 ret = dma_async_is_complete(cookie, last_complete, last_used); 1027 ret = dma_async_is_complete(cookie, last_complete, last_used);
1022 } 1028 }
1023 1029
1024 spin_unlock_bh(&atchan->lock); 1030 spin_unlock_irqrestore(&atchan->lock, flags);
1025 1031
1026 if (ret != DMA_SUCCESS) 1032 if (ret != DMA_SUCCESS)
1027 dma_set_tx_state(txstate, last_complete, last_used, 1033 dma_set_tx_state(txstate, last_complete, last_used,
@@ -1029,7 +1035,7 @@ atc_tx_status(struct dma_chan *chan,
1029 else 1035 else
1030 dma_set_tx_state(txstate, last_complete, last_used, 0); 1036 dma_set_tx_state(txstate, last_complete, last_used, 0);
1031 1037
1032 if (test_bit(ATC_IS_PAUSED, &atchan->status)) 1038 if (atc_chan_is_paused(atchan))
1033 ret = DMA_PAUSED; 1039 ret = DMA_PAUSED;
1034 1040
1035 dev_vdbg(chan2dev(chan), "tx_status %d: cookie = %d (d%d, u%d)\n", 1041 dev_vdbg(chan2dev(chan), "tx_status %d: cookie = %d (d%d, u%d)\n",
@@ -1046,18 +1052,19 @@ atc_tx_status(struct dma_chan *chan,
1046static void atc_issue_pending(struct dma_chan *chan) 1052static void atc_issue_pending(struct dma_chan *chan)
1047{ 1053{
1048 struct at_dma_chan *atchan = to_at_dma_chan(chan); 1054 struct at_dma_chan *atchan = to_at_dma_chan(chan);
1055 unsigned long flags;
1049 1056
1050 dev_vdbg(chan2dev(chan), "issue_pending\n"); 1057 dev_vdbg(chan2dev(chan), "issue_pending\n");
1051 1058
1052 /* Not needed for cyclic transfers */ 1059 /* Not needed for cyclic transfers */
1053 if (test_bit(ATC_IS_CYCLIC, &atchan->status)) 1060 if (atc_chan_is_cyclic(atchan))
1054 return; 1061 return;
1055 1062
1056 spin_lock_bh(&atchan->lock); 1063 spin_lock_irqsave(&atchan->lock, flags);
1057 if (!atc_chan_is_enabled(atchan)) { 1064 if (!atc_chan_is_enabled(atchan)) {
1058 atc_advance_work(atchan); 1065 atc_advance_work(atchan);
1059 } 1066 }
1060 spin_unlock_bh(&atchan->lock); 1067 spin_unlock_irqrestore(&atchan->lock, flags);
1061} 1068}
1062 1069
1063/** 1070/**
@@ -1073,6 +1080,7 @@ static int atc_alloc_chan_resources(struct dma_chan *chan)
1073 struct at_dma *atdma = to_at_dma(chan->device); 1080 struct at_dma *atdma = to_at_dma(chan->device);
1074 struct at_desc *desc; 1081 struct at_desc *desc;
1075 struct at_dma_slave *atslave; 1082 struct at_dma_slave *atslave;
1083 unsigned long flags;
1076 int i; 1084 int i;
1077 u32 cfg; 1085 u32 cfg;
1078 LIST_HEAD(tmp_list); 1086 LIST_HEAD(tmp_list);
@@ -1116,11 +1124,11 @@ static int atc_alloc_chan_resources(struct dma_chan *chan)
1116 list_add_tail(&desc->desc_node, &tmp_list); 1124 list_add_tail(&desc->desc_node, &tmp_list);
1117 } 1125 }
1118 1126
1119 spin_lock_bh(&atchan->lock); 1127 spin_lock_irqsave(&atchan->lock, flags);
1120 atchan->descs_allocated = i; 1128 atchan->descs_allocated = i;
1121 list_splice(&tmp_list, &atchan->free_list); 1129 list_splice(&tmp_list, &atchan->free_list);
1122 atchan->completed_cookie = chan->cookie = 1; 1130 atchan->completed_cookie = chan->cookie = 1;
1123 spin_unlock_bh(&atchan->lock); 1131 spin_unlock_irqrestore(&atchan->lock, flags);
1124 1132
1125 /* channel parameters */ 1133 /* channel parameters */
1126 channel_writel(atchan, CFG, cfg); 1134 channel_writel(atchan, CFG, cfg);
@@ -1293,15 +1301,13 @@ static int __init at_dma_probe(struct platform_device *pdev)
1293 if (dma_has_cap(DMA_MEMCPY, atdma->dma_common.cap_mask)) 1301 if (dma_has_cap(DMA_MEMCPY, atdma->dma_common.cap_mask))
1294 atdma->dma_common.device_prep_dma_memcpy = atc_prep_dma_memcpy; 1302 atdma->dma_common.device_prep_dma_memcpy = atc_prep_dma_memcpy;
1295 1303
1296 if (dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask)) 1304 if (dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask)) {
1297 atdma->dma_common.device_prep_slave_sg = atc_prep_slave_sg; 1305 atdma->dma_common.device_prep_slave_sg = atc_prep_slave_sg;
1298 1306 /* controller can do slave DMA: can trigger cyclic transfers */
1299 if (dma_has_cap(DMA_CYCLIC, atdma->dma_common.cap_mask)) 1307 dma_cap_set(DMA_CYCLIC, atdma->dma_common.cap_mask);
1300 atdma->dma_common.device_prep_dma_cyclic = atc_prep_dma_cyclic; 1308 atdma->dma_common.device_prep_dma_cyclic = atc_prep_dma_cyclic;
1301
1302 if (dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask) ||
1303 dma_has_cap(DMA_CYCLIC, atdma->dma_common.cap_mask))
1304 atdma->dma_common.device_control = atc_control; 1309 atdma->dma_common.device_control = atc_control;
1310 }
1305 1311
1306 dma_writel(atdma, EN, AT_DMA_ENABLE); 1312 dma_writel(atdma, EN, AT_DMA_ENABLE);
1307 1313
@@ -1377,27 +1383,112 @@ static void at_dma_shutdown(struct platform_device *pdev)
1377 clk_disable(atdma->clk); 1383 clk_disable(atdma->clk);
1378} 1384}
1379 1385
1386static int at_dma_prepare(struct device *dev)
1387{
1388 struct platform_device *pdev = to_platform_device(dev);
1389 struct at_dma *atdma = platform_get_drvdata(pdev);
1390 struct dma_chan *chan, *_chan;
1391
1392 list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels,
1393 device_node) {
1394 struct at_dma_chan *atchan = to_at_dma_chan(chan);
1395 /* wait for transaction completion (except in cyclic case) */
1396 if (atc_chan_is_enabled(atchan) && !atc_chan_is_cyclic(atchan))
1397 return -EAGAIN;
1398 }
1399 return 0;
1400}
1401
1402static void atc_suspend_cyclic(struct at_dma_chan *atchan)
1403{
1404 struct dma_chan *chan = &atchan->chan_common;
1405
1406 /* Channel should be paused by user
1407 * do it anyway even if it is not done already */
1408 if (!atc_chan_is_paused(atchan)) {
1409 dev_warn(chan2dev(chan),
1410 "cyclic channel not paused, should be done by channel user\n");
1411 atc_control(chan, DMA_PAUSE, 0);
1412 }
1413
1414 /* now preserve additional data for cyclic operations */
1415 /* next descriptor address in the cyclic list */
1416 atchan->save_dscr = channel_readl(atchan, DSCR);
1417
1418 vdbg_dump_regs(atchan);
1419}
1420
1380static int at_dma_suspend_noirq(struct device *dev) 1421static int at_dma_suspend_noirq(struct device *dev)
1381{ 1422{
1382 struct platform_device *pdev = to_platform_device(dev); 1423 struct platform_device *pdev = to_platform_device(dev);
1383 struct at_dma *atdma = platform_get_drvdata(pdev); 1424 struct at_dma *atdma = platform_get_drvdata(pdev);
1425 struct dma_chan *chan, *_chan;
1384 1426
1385 at_dma_off(platform_get_drvdata(pdev)); 1427 /* preserve data */
1428 list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels,
1429 device_node) {
1430 struct at_dma_chan *atchan = to_at_dma_chan(chan);
1431
1432 if (atc_chan_is_cyclic(atchan))
1433 atc_suspend_cyclic(atchan);
1434 atchan->save_cfg = channel_readl(atchan, CFG);
1435 }
1436 atdma->save_imr = dma_readl(atdma, EBCIMR);
1437
1438 /* disable DMA controller */
1439 at_dma_off(atdma);
1386 clk_disable(atdma->clk); 1440 clk_disable(atdma->clk);
1387 return 0; 1441 return 0;
1388} 1442}
1389 1443
1444static void atc_resume_cyclic(struct at_dma_chan *atchan)
1445{
1446 struct at_dma *atdma = to_at_dma(atchan->chan_common.device);
1447
1448 /* restore channel status for cyclic descriptors list:
1449 * next descriptor in the cyclic list at the time of suspend */
1450 channel_writel(atchan, SADDR, 0);
1451 channel_writel(atchan, DADDR, 0);
1452 channel_writel(atchan, CTRLA, 0);
1453 channel_writel(atchan, CTRLB, 0);
1454 channel_writel(atchan, DSCR, atchan->save_dscr);
1455 dma_writel(atdma, CHER, atchan->mask);
1456
1457 /* channel pause status should be removed by channel user
1458 * We cannot take the initiative to do it here */
1459
1460 vdbg_dump_regs(atchan);
1461}
1462
1390static int at_dma_resume_noirq(struct device *dev) 1463static int at_dma_resume_noirq(struct device *dev)
1391{ 1464{
1392 struct platform_device *pdev = to_platform_device(dev); 1465 struct platform_device *pdev = to_platform_device(dev);
1393 struct at_dma *atdma = platform_get_drvdata(pdev); 1466 struct at_dma *atdma = platform_get_drvdata(pdev);
1467 struct dma_chan *chan, *_chan;
1394 1468
1469 /* bring back DMA controller */
1395 clk_enable(atdma->clk); 1470 clk_enable(atdma->clk);
1396 dma_writel(atdma, EN, AT_DMA_ENABLE); 1471 dma_writel(atdma, EN, AT_DMA_ENABLE);
1472
1473 /* clear any pending interrupt */
1474 while (dma_readl(atdma, EBCISR))
1475 cpu_relax();
1476
1477 /* restore saved data */
1478 dma_writel(atdma, EBCIER, atdma->save_imr);
1479 list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels,
1480 device_node) {
1481 struct at_dma_chan *atchan = to_at_dma_chan(chan);
1482
1483 channel_writel(atchan, CFG, atchan->save_cfg);
1484 if (atc_chan_is_cyclic(atchan))
1485 atc_resume_cyclic(atchan);
1486 }
1397 return 0; 1487 return 0;
1398} 1488}
1399 1489
1400static const struct dev_pm_ops at_dma_dev_pm_ops = { 1490static const struct dev_pm_ops at_dma_dev_pm_ops = {
1491 .prepare = at_dma_prepare,
1401 .suspend_noirq = at_dma_suspend_noirq, 1492 .suspend_noirq = at_dma_suspend_noirq,
1402 .resume_noirq = at_dma_resume_noirq, 1493 .resume_noirq = at_dma_resume_noirq,
1403}; 1494};
diff --git a/drivers/dma/at_hdmac_regs.h b/drivers/dma/at_hdmac_regs.h
index 087dbf1dd39c..aa4c9aebab7c 100644
--- a/drivers/dma/at_hdmac_regs.h
+++ b/drivers/dma/at_hdmac_regs.h
@@ -204,6 +204,9 @@ enum atc_status {
204 * @status: transmit status information from irq/prep* functions 204 * @status: transmit status information from irq/prep* functions
205 * to tasklet (use atomic operations) 205 * to tasklet (use atomic operations)
206 * @tasklet: bottom half to finish transaction work 206 * @tasklet: bottom half to finish transaction work
207 * @save_cfg: configuration register that is saved on suspend/resume cycle
208 * @save_dscr: for cyclic operations, preserve next descriptor address in
209 * the cyclic list on suspend/resume cycle
207 * @lock: serializes enqueue/dequeue operations to descriptors lists 210 * @lock: serializes enqueue/dequeue operations to descriptors lists
208 * @completed_cookie: identifier for the most recently completed operation 211 * @completed_cookie: identifier for the most recently completed operation
209 * @active_list: list of descriptors dmaengine is being running on 212 * @active_list: list of descriptors dmaengine is being running on
@@ -218,6 +221,8 @@ struct at_dma_chan {
218 u8 mask; 221 u8 mask;
219 unsigned long status; 222 unsigned long status;
220 struct tasklet_struct tasklet; 223 struct tasklet_struct tasklet;
224 u32 save_cfg;
225 u32 save_dscr;
221 226
222 spinlock_t lock; 227 spinlock_t lock;
223 228
@@ -248,6 +253,7 @@ static inline struct at_dma_chan *to_at_dma_chan(struct dma_chan *dchan)
248 * @chan_common: common dmaengine dma_device object members 253 * @chan_common: common dmaengine dma_device object members
249 * @ch_regs: memory mapped register base 254 * @ch_regs: memory mapped register base
250 * @clk: dma controller clock 255 * @clk: dma controller clock
256 * @save_imr: interrupt mask register that is saved on suspend/resume cycle
251 * @all_chan_mask: all channels availlable in a mask 257 * @all_chan_mask: all channels availlable in a mask
252 * @dma_desc_pool: base of DMA descriptor region (DMA address) 258 * @dma_desc_pool: base of DMA descriptor region (DMA address)
253 * @chan: channels table to store at_dma_chan structures 259 * @chan: channels table to store at_dma_chan structures
@@ -256,6 +262,7 @@ struct at_dma {
256 struct dma_device dma_common; 262 struct dma_device dma_common;
257 void __iomem *regs; 263 void __iomem *regs;
258 struct clk *clk; 264 struct clk *clk;
265 u32 save_imr;
259 266
260 u8 all_chan_mask; 267 u8 all_chan_mask;
261 268
@@ -355,6 +362,23 @@ static inline int atc_chan_is_enabled(struct at_dma_chan *atchan)
355 return !!(dma_readl(atdma, CHSR) & atchan->mask); 362 return !!(dma_readl(atdma, CHSR) & atchan->mask);
356} 363}
357 364
365/**
366 * atc_chan_is_paused - test channel pause/resume status
367 * @atchan: channel we want to test status
368 */
369static inline int atc_chan_is_paused(struct at_dma_chan *atchan)
370{
371 return test_bit(ATC_IS_PAUSED, &atchan->status);
372}
373
374/**
375 * atc_chan_is_cyclic - test if given channel has cyclic property set
376 * @atchan: channel we want to test status
377 */
378static inline int atc_chan_is_cyclic(struct at_dma_chan *atchan)
379{
380 return test_bit(ATC_IS_CYCLIC, &atchan->status);
381}
358 382
359/** 383/**
360 * set_desc_eol - set end-of-link to descriptor so it will end transfer 384 * set_desc_eol - set end-of-link to descriptor so it will end transfer
diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
index 765f5ff22304..eb1d8641cf5c 100644
--- a/drivers/dma/dmatest.c
+++ b/drivers/dma/dmatest.c
@@ -10,6 +10,7 @@
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <linux/dma-mapping.h> 11#include <linux/dma-mapping.h>
12#include <linux/dmaengine.h> 12#include <linux/dmaengine.h>
13#include <linux/freezer.h>
13#include <linux/init.h> 14#include <linux/init.h>
14#include <linux/kthread.h> 15#include <linux/kthread.h>
15#include <linux/module.h> 16#include <linux/module.h>
@@ -251,6 +252,7 @@ static int dmatest_func(void *data)
251 int i; 252 int i;
252 253
253 thread_name = current->comm; 254 thread_name = current->comm;
255 set_freezable_with_signal();
254 256
255 ret = -ENOMEM; 257 ret = -ENOMEM;
256 258
@@ -305,7 +307,8 @@ static int dmatest_func(void *data)
305 dma_addr_t dma_srcs[src_cnt]; 307 dma_addr_t dma_srcs[src_cnt];
306 dma_addr_t dma_dsts[dst_cnt]; 308 dma_addr_t dma_dsts[dst_cnt];
307 struct completion cmp; 309 struct completion cmp;
308 unsigned long tmo = msecs_to_jiffies(timeout); 310 unsigned long start, tmo, end = 0 /* compiler... */;
311 bool reload = true;
309 u8 align = 0; 312 u8 align = 0;
310 313
311 total_tests++; 314 total_tests++;
@@ -404,7 +407,17 @@ static int dmatest_func(void *data)
404 } 407 }
405 dma_async_issue_pending(chan); 408 dma_async_issue_pending(chan);
406 409
407 tmo = wait_for_completion_timeout(&cmp, tmo); 410 do {
411 start = jiffies;
412 if (reload)
413 end = start + msecs_to_jiffies(timeout);
414 else if (end <= start)
415 end = start + 1;
416 tmo = wait_for_completion_interruptible_timeout(&cmp,
417 end - start);
418 reload = try_to_freeze();
419 } while (tmo == -ERESTARTSYS);
420
408 status = dma_async_is_tx_complete(chan, cookie, NULL, NULL); 421 status = dma_async_is_tx_complete(chan, cookie, NULL, NULL);
409 422
410 if (tmo == 0) { 423 if (tmo == 0) {
@@ -477,6 +490,8 @@ err_srcs:
477 pr_notice("%s: terminating after %u tests, %u failures (status %d)\n", 490 pr_notice("%s: terminating after %u tests, %u failures (status %d)\n",
478 thread_name, total_tests, failed_tests, ret); 491 thread_name, total_tests, failed_tests, ret);
479 492
493 /* terminate all transfers on specified channels */
494 chan->device->device_control(chan, DMA_TERMINATE_ALL, 0);
480 if (iterations > 0) 495 if (iterations > 0)
481 while (!kthread_should_stop()) { 496 while (!kthread_should_stop()) {
482 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit); 497 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit);
@@ -499,6 +514,10 @@ static void dmatest_cleanup_channel(struct dmatest_chan *dtc)
499 list_del(&thread->node); 514 list_del(&thread->node);
500 kfree(thread); 515 kfree(thread);
501 } 516 }
517
518 /* terminate all transfers on specified channels */
519 dtc->chan->device->device_control(dtc->chan, DMA_TERMINATE_ALL, 0);
520
502 kfree(dtc); 521 kfree(dtc);
503} 522}
504 523
diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 7bd7e98548cd..b5cc27dc9a51 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -318,6 +318,7 @@ struct sdma_engine {
318 dma_addr_t context_phys; 318 dma_addr_t context_phys;
319 struct dma_device dma_device; 319 struct dma_device dma_device;
320 struct clk *clk; 320 struct clk *clk;
321 struct mutex channel_0_lock;
321 struct sdma_script_start_addrs *script_addrs; 322 struct sdma_script_start_addrs *script_addrs;
322}; 323};
323 324
@@ -415,11 +416,15 @@ static int sdma_load_script(struct sdma_engine *sdma, void *buf, int size,
415 dma_addr_t buf_phys; 416 dma_addr_t buf_phys;
416 int ret; 417 int ret;
417 418
419 mutex_lock(&sdma->channel_0_lock);
420
418 buf_virt = dma_alloc_coherent(NULL, 421 buf_virt = dma_alloc_coherent(NULL,
419 size, 422 size,
420 &buf_phys, GFP_KERNEL); 423 &buf_phys, GFP_KERNEL);
421 if (!buf_virt) 424 if (!buf_virt) {
422 return -ENOMEM; 425 ret = -ENOMEM;
426 goto err_out;
427 }
423 428
424 bd0->mode.command = C0_SETPM; 429 bd0->mode.command = C0_SETPM;
425 bd0->mode.status = BD_DONE | BD_INTR | BD_WRAP | BD_EXTD; 430 bd0->mode.status = BD_DONE | BD_INTR | BD_WRAP | BD_EXTD;
@@ -433,6 +438,9 @@ static int sdma_load_script(struct sdma_engine *sdma, void *buf, int size,
433 438
434 dma_free_coherent(NULL, size, buf_virt, buf_phys); 439 dma_free_coherent(NULL, size, buf_virt, buf_phys);
435 440
441err_out:
442 mutex_unlock(&sdma->channel_0_lock);
443
436 return ret; 444 return ret;
437} 445}
438 446
@@ -656,6 +664,8 @@ static int sdma_load_context(struct sdma_channel *sdmac)
656 dev_dbg(sdma->dev, "event_mask0 = 0x%08x\n", sdmac->event_mask0); 664 dev_dbg(sdma->dev, "event_mask0 = 0x%08x\n", sdmac->event_mask0);
657 dev_dbg(sdma->dev, "event_mask1 = 0x%08x\n", sdmac->event_mask1); 665 dev_dbg(sdma->dev, "event_mask1 = 0x%08x\n", sdmac->event_mask1);
658 666
667 mutex_lock(&sdma->channel_0_lock);
668
659 memset(context, 0, sizeof(*context)); 669 memset(context, 0, sizeof(*context));
660 context->channel_state.pc = load_address; 670 context->channel_state.pc = load_address;
661 671
@@ -676,6 +686,8 @@ static int sdma_load_context(struct sdma_channel *sdmac)
676 686
677 ret = sdma_run_channel(&sdma->channel[0]); 687 ret = sdma_run_channel(&sdma->channel[0]);
678 688
689 mutex_unlock(&sdma->channel_0_lock);
690
679 return ret; 691 return ret;
680} 692}
681 693
@@ -1131,18 +1143,17 @@ static void sdma_add_scripts(struct sdma_engine *sdma,
1131 saddr_arr[i] = addr_arr[i]; 1143 saddr_arr[i] = addr_arr[i];
1132} 1144}
1133 1145
1134static int __init sdma_get_firmware(struct sdma_engine *sdma, 1146static void sdma_load_firmware(const struct firmware *fw, void *context)
1135 const char *fw_name)
1136{ 1147{
1137 const struct firmware *fw; 1148 struct sdma_engine *sdma = context;
1138 const struct sdma_firmware_header *header; 1149 const struct sdma_firmware_header *header;
1139 int ret;
1140 const struct sdma_script_start_addrs *addr; 1150 const struct sdma_script_start_addrs *addr;
1141 unsigned short *ram_code; 1151 unsigned short *ram_code;
1142 1152
1143 ret = request_firmware(&fw, fw_name, sdma->dev); 1153 if (!fw) {
1144 if (ret) 1154 dev_err(sdma->dev, "firmware not found\n");
1145 return ret; 1155 return;
1156 }
1146 1157
1147 if (fw->size < sizeof(*header)) 1158 if (fw->size < sizeof(*header))
1148 goto err_firmware; 1159 goto err_firmware;
@@ -1172,6 +1183,16 @@ static int __init sdma_get_firmware(struct sdma_engine *sdma,
1172 1183
1173err_firmware: 1184err_firmware:
1174 release_firmware(fw); 1185 release_firmware(fw);
1186}
1187
1188static int __init sdma_get_firmware(struct sdma_engine *sdma,
1189 const char *fw_name)
1190{
1191 int ret;
1192
1193 ret = request_firmware_nowait(THIS_MODULE,
1194 FW_ACTION_HOTPLUG, fw_name, sdma->dev,
1195 GFP_KERNEL, sdma, sdma_load_firmware);
1175 1196
1176 return ret; 1197 return ret;
1177} 1198}
@@ -1269,11 +1290,14 @@ static int __init sdma_probe(struct platform_device *pdev)
1269 struct sdma_platform_data *pdata = pdev->dev.platform_data; 1290 struct sdma_platform_data *pdata = pdev->dev.platform_data;
1270 int i; 1291 int i;
1271 struct sdma_engine *sdma; 1292 struct sdma_engine *sdma;
1293 s32 *saddr_arr;
1272 1294
1273 sdma = kzalloc(sizeof(*sdma), GFP_KERNEL); 1295 sdma = kzalloc(sizeof(*sdma), GFP_KERNEL);
1274 if (!sdma) 1296 if (!sdma)
1275 return -ENOMEM; 1297 return -ENOMEM;
1276 1298
1299 mutex_init(&sdma->channel_0_lock);
1300
1277 sdma->dev = &pdev->dev; 1301 sdma->dev = &pdev->dev;
1278 1302
1279 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1303 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1310,6 +1334,11 @@ static int __init sdma_probe(struct platform_device *pdev)
1310 goto err_alloc; 1334 goto err_alloc;
1311 } 1335 }
1312 1336
1337 /* initially no scripts available */
1338 saddr_arr = (s32 *)sdma->script_addrs;
1339 for (i = 0; i < SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1; i++)
1340 saddr_arr[i] = -EINVAL;
1341
1313 if (of_id) 1342 if (of_id)
1314 pdev->id_entry = of_id->data; 1343 pdev->id_entry = of_id->data;
1315 sdma->devtype = pdev->id_entry->driver_data; 1344 sdma->devtype = pdev->id_entry->driver_data;
diff --git a/drivers/dma/mxs-dma.c b/drivers/dma/mxs-dma.c
index be641cbd36fc..b4588bdd98bb 100644
--- a/drivers/dma/mxs-dma.c
+++ b/drivers/dma/mxs-dma.c
@@ -130,6 +130,23 @@ struct mxs_dma_engine {
130 struct mxs_dma_chan mxs_chans[MXS_DMA_CHANNELS]; 130 struct mxs_dma_chan mxs_chans[MXS_DMA_CHANNELS];
131}; 131};
132 132
133static inline void mxs_dma_clkgate(struct mxs_dma_chan *mxs_chan, int enable)
134{
135 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
136 int chan_id = mxs_chan->chan.chan_id;
137 int set_clr = enable ? MXS_CLR_ADDR : MXS_SET_ADDR;
138
139 /* enable apbh channel clock */
140 if (dma_is_apbh()) {
141 if (apbh_is_old())
142 writel(1 << (chan_id + BP_APBH_CTRL0_CLKGATE_CHANNEL),
143 mxs_dma->base + HW_APBHX_CTRL0 + set_clr);
144 else
145 writel(1 << chan_id,
146 mxs_dma->base + HW_APBHX_CTRL0 + set_clr);
147 }
148}
149
133static void mxs_dma_reset_chan(struct mxs_dma_chan *mxs_chan) 150static void mxs_dma_reset_chan(struct mxs_dma_chan *mxs_chan)
134{ 151{
135 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma; 152 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
@@ -148,38 +165,21 @@ static void mxs_dma_enable_chan(struct mxs_dma_chan *mxs_chan)
148 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma; 165 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
149 int chan_id = mxs_chan->chan.chan_id; 166 int chan_id = mxs_chan->chan.chan_id;
150 167
168 /* clkgate needs to be enabled before writing other registers */
169 mxs_dma_clkgate(mxs_chan, 1);
170
151 /* set cmd_addr up */ 171 /* set cmd_addr up */
152 writel(mxs_chan->ccw_phys, 172 writel(mxs_chan->ccw_phys,
153 mxs_dma->base + HW_APBHX_CHn_NXTCMDAR(chan_id)); 173 mxs_dma->base + HW_APBHX_CHn_NXTCMDAR(chan_id));
154 174
155 /* enable apbh channel clock */
156 if (dma_is_apbh()) {
157 if (apbh_is_old())
158 writel(1 << (chan_id + BP_APBH_CTRL0_CLKGATE_CHANNEL),
159 mxs_dma->base + HW_APBHX_CTRL0 + MXS_CLR_ADDR);
160 else
161 writel(1 << chan_id,
162 mxs_dma->base + HW_APBHX_CTRL0 + MXS_CLR_ADDR);
163 }
164
165 /* write 1 to SEMA to kick off the channel */ 175 /* write 1 to SEMA to kick off the channel */
166 writel(1, mxs_dma->base + HW_APBHX_CHn_SEMA(chan_id)); 176 writel(1, mxs_dma->base + HW_APBHX_CHn_SEMA(chan_id));
167} 177}
168 178
169static void mxs_dma_disable_chan(struct mxs_dma_chan *mxs_chan) 179static void mxs_dma_disable_chan(struct mxs_dma_chan *mxs_chan)
170{ 180{
171 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
172 int chan_id = mxs_chan->chan.chan_id;
173
174 /* disable apbh channel clock */ 181 /* disable apbh channel clock */
175 if (dma_is_apbh()) { 182 mxs_dma_clkgate(mxs_chan, 0);
176 if (apbh_is_old())
177 writel(1 << (chan_id + BP_APBH_CTRL0_CLKGATE_CHANNEL),
178 mxs_dma->base + HW_APBHX_CTRL0 + MXS_SET_ADDR);
179 else
180 writel(1 << chan_id,
181 mxs_dma->base + HW_APBHX_CTRL0 + MXS_SET_ADDR);
182 }
183 183
184 mxs_chan->status = DMA_SUCCESS; 184 mxs_chan->status = DMA_SUCCESS;
185} 185}
@@ -338,7 +338,10 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
338 if (ret) 338 if (ret)
339 goto err_clk; 339 goto err_clk;
340 340
341 /* clkgate needs to be enabled for reset to finish */
342 mxs_dma_clkgate(mxs_chan, 1);
341 mxs_dma_reset_chan(mxs_chan); 343 mxs_dma_reset_chan(mxs_chan);
344 mxs_dma_clkgate(mxs_chan, 0);
342 345
343 dma_async_tx_descriptor_init(&mxs_chan->desc, chan); 346 dma_async_tx_descriptor_init(&mxs_chan->desc, chan);
344 mxs_chan->desc.tx_submit = mxs_dma_tx_submit; 347 mxs_chan->desc.tx_submit = mxs_dma_tx_submit;