]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge branch 'next' of git://git.infradead.org/users/vkoul/slave-dma
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 29 Mar 2012 22:34:57 +0000 (15:34 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 29 Mar 2012 22:34:57 +0000 (15:34 -0700)
Pull slave-dmaengine update from Vinod Koul:
 "This includes the cookie cleanup by Russell, the addition of context
  parameter for dmaengine APIs, more arm dmaengine driver cleanup by
  moving code to dmaengine, this time for imx by Javier and pl330 by
  Boojin along with the usual driver fixes."

Fix up some fairly trivial conflicts with various other cleanups.

* 'next' of git://git.infradead.org/users/vkoul/slave-dma: (67 commits)
  dmaengine: imx: fix the build failure on x86_64
  dmaengine: i.MX: Fix merge of cookie branch.
  dmaengine: i.MX: Add support for interleaved transfers.
  dmaengine: imx-dma: use 'dev_dbg' and 'dev_warn' for messages.
  dmaengine: imx-dma: remove 'imx_dmav1_baseaddr' and 'dma_clk'.
  dmaengine: imx-dma: remove unused arg of imxdma_sg_next.
  dmaengine: imx-dma: remove internal structure.
  dmaengine: imx-dma: remove 'resbytes' field of 'internal' structure.
  dmaengine: imx-dma: remove 'in_use' field of 'internal' structure.
  dmaengine: imx-dma: remove sg member from internal structure.
  dmaengine: imx-dma: remove 'imxdma_setup_sg_hw' function.
  dmaengine: imx-dma: remove 'imxdma_config_channel_hw' function.
  dmaengine: imx-dma: remove 'imxdma_setup_mem2mem_hw' function.
  dmaengine: imx-dma: remove dma_mode member of internal structure.
  dmaengine: imx-dma: remove data member from internal structure.
  dmaengine: imx-dma: merge old dma-v1.c with imx-dma.c
  dmaengine: at_hdmac: add slave config operation
  dmaengine: add context parameter to prep_slave_sg and prep_dma_cyclic
  dmaengine/dma_slave: introduce inline wrappers
  dma: imx-sdma: Treat firmware messages as warnings instead of erros
  ...

26 files changed:
1  2 
arch/arm/common/Kconfig
arch/arm/common/Makefile
arch/arm/mach-at91/at91sam9g45_devices.c
arch/arm/mach-imx/Kconfig
arch/arm/mach-imx/Makefile
arch/arm/plat-samsung/dma-ops.c
arch/avr32/mach-at32ap/at32ap700x.c
drivers/dma/Kconfig
drivers/dma/imx-dma.c
drivers/dma/imx-sdma.c
drivers/dma/iop-adma.c
drivers/dma/pl330.c
drivers/mmc/host/atmel-mci.c
drivers/mmc/host/mmci.c
drivers/mmc/host/sh_mmcif.c
drivers/mmc/host/tmio_mmc_dma.c
drivers/mtd/nand/gpmi-nand/gpmi-lib.c
drivers/net/ethernet/micrel/ks8842.c
drivers/spi/spi-pl022.c
drivers/spi/spi-topcliff-pch.c
drivers/tty/serial/amba-pl011.c
drivers/tty/serial/pch_uart.c
drivers/tty/serial/sh-sci.c
drivers/usb/renesas_usbhs/fifo.c
include/linux/dmaengine.h
sound/soc/imx/imx-pcm-dma-mx2.c

diff --combined arch/arm/common/Kconfig
index 3bb1d7589bd9ec52a864487145cd88a428296253,a43c758ff0daec0469737add7398215cd701e0fa..283fa1d804f4d34208e544f5c3064a72457afc52
@@@ -24,9 -24,6 +24,6 @@@ config ARM_VIC_N
  config ICST
        bool
  
- config PL330
-       bool
  config SA1111
        bool
        select DMABOUNCE if !ARCH_PXA
@@@ -35,6 -32,9 +32,6 @@@ config DMABOUNC
        bool
        select ZONE_DMA
  
 -config TIMER_ACORN
 -      bool
 -
  config SHARP_LOCOMO
        bool
  
diff --combined arch/arm/common/Makefile
index 69feafe7286c152f8eed73b998f2fe2e70347de9,107d6d97c6e1f10df57abf5e2e8ab6aa2f396638..215816f1775f5a7a38ed4d5ea5d225aabbad337d
@@@ -5,10 -5,10 +5,9 @@@
  obj-$(CONFIG_ARM_GIC)         += gic.o
  obj-$(CONFIG_ARM_VIC)         += vic.o
  obj-$(CONFIG_ICST)            += icst.o
- obj-$(CONFIG_PL330)           += pl330.o
  obj-$(CONFIG_SA1111)          += sa1111.o
  obj-$(CONFIG_PCI_HOST_VIA82C505) += via82c505.o
  obj-$(CONFIG_DMABOUNCE)               += dmabounce.o
 -obj-$(CONFIG_TIMER_ACORN)     += time-acorn.o
  obj-$(CONFIG_SHARP_LOCOMO)    += locomo.o
  obj-$(CONFIG_SHARP_PARAM)     += sharpsl_param.o
  obj-$(CONFIG_SHARP_SCOOP)     += scoop.o
index 4320b2096789c73a4c5110af51324472f80890c4,1f89b206c26ff8fa7b35747cdf44f01fdd908f8b..698479f1e197cf5725139bf135eb0c89f0d5d715
@@@ -14,7 -14,6 +14,7 @@@
  
  #include <linux/dma-mapping.h>
  #include <linux/gpio.h>
 +#include <linux/clk.h>
  #include <linux/platform_device.h>
  #include <linux/i2c-gpio.h>
  #include <linux/atmel-mci.h>
  #include <mach/board.h>
  #include <mach/at91sam9g45.h>
  #include <mach/at91sam9g45_matrix.h>
 +#include <mach/at91_matrix.h>
  #include <mach/at91sam9_smc.h>
  #include <mach/at_hdmac.h>
  #include <mach/atmel-mci.h>
  
 +#include <media/atmel-isi.h>
 +
  #include "generic.h"
 +#include "clock.h"
  
  
  /* --------------------------------------------------------------------
  #if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
  static u64 hdmac_dmamask = DMA_BIT_MASK(32);
  
 -static struct at_dma_platform_data atdma_pdata = {
 -      .nr_channels    = 8,
 -};
 -
  static struct resource hdmac_resources[] = {
        [0] = {
                .start  = AT91SAM9G45_BASE_DMA,
  };
  
  static struct platform_device at_hdmac_device = {
 -      .name           = "at_hdmac",
 +      .name           = "at91sam9g45_dma",
        .id             = -1,
        .dev            = {
                                .dma_mask               = &hdmac_dmamask,
                                .coherent_dma_mask      = DMA_BIT_MASK(32),
 -                              .platform_data          = &atdma_pdata,
        },
        .resource       = hdmac_resources,
        .num_resources  = ARRAY_SIZE(hdmac_resources),
  
  void __init at91_add_device_hdmac(void)
  {
 -      dma_cap_set(DMA_MEMCPY, atdma_pdata.cap_mask);
 -      dma_cap_set(DMA_SLAVE, atdma_pdata.cap_mask);
 -      platform_device_register(&at_hdmac_device);
 +#if defined(CONFIG_OF)
 +      struct device_node *of_node =
 +              of_find_node_by_name(NULL, "dma-controller");
 +
 +      if (of_node)
 +              of_node_put(of_node);
 +      else
 +#endif
 +              platform_device_register(&at_hdmac_device);
  }
  #else
  void __init at91_add_device_hdmac(void) {}
@@@ -437,7 -431,6 +437,6 @@@ void __init at91_add_device_mci(short m
  
        /* DMA slave channel configuration */
        atslave->dma_dev = &at_hdmac_device.dev;
-       atslave->reg_width = AT_DMA_SLAVE_WIDTH_32BIT;
        atslave->cfg = ATC_FIFOCFG_HALFFIFO
                        | ATC_SRC_H2SEL_HW | ATC_DST_H2SEL_HW;
        atslave->ctrla = ATC_SCSIZE_16 | ATC_DCSIZE_16;
@@@ -558,8 -551,8 +557,8 @@@ void __init at91_add_device_nand(struc
        if (!data)
                return;
  
 -      csa = at91_sys_read(AT91_MATRIX_EBICSA);
 -      at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA);
 +      csa = at91_matrix_read(AT91_MATRIX_EBICSA);
 +      at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA);
  
        /* enable pin */
        if (gpio_is_valid(data->enable_pin))
@@@ -875,96 -868,6 +874,96 @@@ void __init at91_add_device_ac97(struc
  void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
  #endif
  
 +/* --------------------------------------------------------------------
 + *  Image Sensor Interface
 + * -------------------------------------------------------------------- */
 +#if defined(CONFIG_VIDEO_ATMEL_ISI) || defined(CONFIG_VIDEO_ATMEL_ISI_MODULE)
 +static u64 isi_dmamask = DMA_BIT_MASK(32);
 +static struct isi_platform_data isi_data;
 +
 +struct resource isi_resources[] = {
 +      [0] = {
 +              .start  = AT91SAM9G45_BASE_ISI,
 +              .end    = AT91SAM9G45_BASE_ISI + SZ_16K - 1,
 +              .flags  = IORESOURCE_MEM,
 +      },
 +      [1] = {
 +              .start  = AT91SAM9G45_ID_ISI,
 +              .end    = AT91SAM9G45_ID_ISI,
 +              .flags  = IORESOURCE_IRQ,
 +      },
 +};
 +
 +static struct platform_device at91sam9g45_isi_device = {
 +      .name           = "atmel_isi",
 +      .id             = 0,
 +      .dev            = {
 +                      .dma_mask               = &isi_dmamask,
 +                      .coherent_dma_mask      = DMA_BIT_MASK(32),
 +                      .platform_data          = &isi_data,
 +      },
 +      .resource       = isi_resources,
 +      .num_resources  = ARRAY_SIZE(isi_resources),
 +};
 +
 +static struct clk_lookup isi_mck_lookups[] = {
 +      CLKDEV_CON_DEV_ID("isi_mck", "atmel_isi.0", NULL),
 +};
 +
 +void __init at91_add_device_isi(struct isi_platform_data *data,
 +              bool use_pck_as_mck)
 +{
 +      struct clk *pck;
 +      struct clk *parent;
 +
 +      if (!data)
 +              return;
 +      isi_data = *data;
 +
 +      at91_set_A_periph(AT91_PIN_PB20, 0);    /* ISI_D0 */
 +      at91_set_A_periph(AT91_PIN_PB21, 0);    /* ISI_D1 */
 +      at91_set_A_periph(AT91_PIN_PB22, 0);    /* ISI_D2 */
 +      at91_set_A_periph(AT91_PIN_PB23, 0);    /* ISI_D3 */
 +      at91_set_A_periph(AT91_PIN_PB24, 0);    /* ISI_D4 */
 +      at91_set_A_periph(AT91_PIN_PB25, 0);    /* ISI_D5 */
 +      at91_set_A_periph(AT91_PIN_PB26, 0);    /* ISI_D6 */
 +      at91_set_A_periph(AT91_PIN_PB27, 0);    /* ISI_D7 */
 +      at91_set_A_periph(AT91_PIN_PB28, 0);    /* ISI_PCK */
 +      at91_set_A_periph(AT91_PIN_PB30, 0);    /* ISI_HSYNC */
 +      at91_set_A_periph(AT91_PIN_PB29, 0);    /* ISI_VSYNC */
 +      at91_set_B_periph(AT91_PIN_PB8, 0);     /* ISI_PD8 */
 +      at91_set_B_periph(AT91_PIN_PB9, 0);     /* ISI_PD9 */
 +      at91_set_B_periph(AT91_PIN_PB10, 0);    /* ISI_PD10 */
 +      at91_set_B_periph(AT91_PIN_PB11, 0);    /* ISI_PD11 */
 +
 +      platform_device_register(&at91sam9g45_isi_device);
 +
 +      if (use_pck_as_mck) {
 +              at91_set_B_periph(AT91_PIN_PB31, 0);    /* ISI_MCK (PCK1) */
 +
 +              pck = clk_get(NULL, "pck1");
 +              parent = clk_get(NULL, "plla");
 +
 +              BUG_ON(IS_ERR(pck) || IS_ERR(parent));
 +
 +              if (clk_set_parent(pck, parent)) {
 +                      pr_err("Failed to set PCK's parent\n");
 +              } else {
 +                      /* Register PCK as ISI_MCK */
 +                      isi_mck_lookups[0].clk = pck;
 +                      clkdev_add_table(isi_mck_lookups,
 +                                      ARRAY_SIZE(isi_mck_lookups));
 +              }
 +
 +              clk_put(pck);
 +              clk_put(parent);
 +      }
 +}
 +#else
 +void __init at91_add_device_isi(struct isi_platform_data *data,
 +              bool use_pck_as_mck) {}
 +#endif
 +
  
  /* --------------------------------------------------------------------
   *  LCD Controller
@@@ -1052,7 -955,7 +1051,7 @@@ void __init at91_add_device_lcdc(struc
  static struct resource tcb0_resources[] = {
        [0] = {
                .start  = AT91SAM9G45_BASE_TCB0,
 -              .end    = AT91SAM9G45_BASE_TCB0 + SZ_16K - 1,
 +              .end    = AT91SAM9G45_BASE_TCB0 + SZ_256 - 1,
                .flags  = IORESOURCE_MEM,
        },
        [1] = {
@@@ -1073,7 -976,7 +1072,7 @@@ static struct platform_device at91sam9g
  static struct resource tcb1_resources[] = {
        [0] = {
                .start  = AT91SAM9G45_BASE_TCB1,
 -              .end    = AT91SAM9G45_BASE_TCB1 + SZ_16K - 1,
 +              .end    = AT91SAM9G45_BASE_TCB1 + SZ_256 - 1,
                .flags  = IORESOURCE_MEM,
        },
        [1] = {
@@@ -1090,25 -993,8 +1089,25 @@@ static struct platform_device at91sam9g
        .num_resources  = ARRAY_SIZE(tcb1_resources),
  };
  
 +#if defined(CONFIG_OF)
 +static struct of_device_id tcb_ids[] = {
 +      { .compatible = "atmel,at91rm9200-tcb" },
 +      { /*sentinel*/ }
 +};
 +#endif
 +
  static void __init at91_add_device_tc(void)
  {
 +#if defined(CONFIG_OF)
 +      struct device_node *np;
 +
 +      np = of_find_matching_node(NULL, tcb_ids);
 +      if (np) {
 +              of_node_put(np);
 +              return;
 +      }
 +#endif
 +
        platform_device_register(&at91sam9g45_tcb0_device);
        platform_device_register(&at91sam9g45_tcb1_device);
  }
@@@ -1211,8 -1097,6 +1210,8 @@@ static struct resource rtt_resources[] 
                .start  = AT91SAM9G45_BASE_RTT,
                .end    = AT91SAM9G45_BASE_RTT + SZ_16 - 1,
                .flags  = IORESOURCE_MEM,
 +      }, {
 +              .flags  = IORESOURCE_MEM,
        }
  };
  
@@@ -1220,32 -1104,11 +1219,32 @@@ static struct platform_device at91sam9g
        .name           = "at91_rtt",
        .id             = 0,
        .resource       = rtt_resources,
 -      .num_resources  = ARRAY_SIZE(rtt_resources),
  };
  
 +#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
 +static void __init at91_add_device_rtt_rtc(void)
 +{
 +      at91sam9g45_rtt_device.name = "rtc-at91sam9";
 +      /*
 +       * The second resource is needed:
 +       * GPBR will serve as the storage for RTC time offset
 +       */
 +      at91sam9g45_rtt_device.num_resources = 2;
 +      rtt_resources[1].start = AT91SAM9G45_BASE_GPBR +
 +                               4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
 +      rtt_resources[1].end = rtt_resources[1].start + 3;
 +}
 +#else
 +static void __init at91_add_device_rtt_rtc(void)
 +{
 +      /* Only one resource is needed: RTT not used as RTC */
 +      at91sam9g45_rtt_device.num_resources = 1;
 +}
 +#endif
 +
  static void __init at91_add_device_rtt(void)
  {
 +      at91_add_device_rtt_rtc();
        platform_device_register(&at91sam9g45_rtt_device);
  }
  
@@@ -1700,6 -1563,7 +1699,6 @@@ static inline void configure_usart3_pin
  }
  
  static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
 -struct platform_device *atmel_default_console_device; /* the serial console device */
  
  void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  {
index 52359f80c42d1b2e2bbe06fc93d1e72d389649e3,3da1421c944f058e2d8aeaafd2050a03b678de4f..7561eca131b0ba989c42afb1a5ec94fbce98f688
@@@ -1,6 -1,3 +1,3 @@@
- config IMX_HAVE_DMA_V1
-       bool
  config HAVE_IMX_GPC
        bool
  
@@@ -22,23 -19,10 +19,22 @@@ config ARCH_MX2
  config MACH_MX27
        bool
  
 +config ARCH_MX5
 +      bool
 +
 +config ARCH_MX50
 +      bool
 +
 +config ARCH_MX51
 +      bool
 +
 +config ARCH_MX53
 +      bool
 +
  config SOC_IMX1
        bool
        select ARCH_MX1
        select CPU_ARM920T
-       select IMX_HAVE_DMA_V1
        select IMX_HAVE_IOMUX_V1
        select MXC_AVIC
  
@@@ -46,7 -30,7 +42,6 @@@ config SOC_IMX2
        bool
        select MACH_MX21
        select CPU_ARM926T
-       select IMX_HAVE_DMA_V1
 -      select ARCH_MXC_AUDMUX_V1
        select IMX_HAVE_IOMUX_V1
        select MXC_AVIC
  
@@@ -54,6 -38,7 +49,6 @@@ config SOC_IMX2
        bool
        select ARCH_MX25
        select CPU_ARM926T
 -      select ARCH_MXC_AUDMUX_V2
        select ARCH_MXC_IOMUX_V3
        select MXC_AVIC
  
@@@ -61,7 -46,7 +56,6 @@@ config SOC_IMX2
        bool
        select MACH_MX27
        select CPU_ARM926T
-       select IMX_HAVE_DMA_V1
 -      select ARCH_MXC_AUDMUX_V1
        select IMX_HAVE_IOMUX_V1
        select MXC_AVIC
  
@@@ -69,6 -54,7 +63,6 @@@ config SOC_IMX3
        bool
        select CPU_V6
        select IMX_HAVE_PLATFORM_MXC_RNGA
 -      select ARCH_MXC_AUDMUX_V2
        select MXC_AVIC
        select SMP_ON_UP if SMP
  
@@@ -76,34 -62,11 +70,34 @@@ config SOC_IMX3
        bool
        select CPU_V6
        select ARCH_MXC_IOMUX_V3
 -      select ARCH_MXC_AUDMUX_V2
        select HAVE_EPIT
        select MXC_AVIC
        select SMP_ON_UP if SMP
  
 +config SOC_IMX5
 +      select CPU_V7
 +      select MXC_TZIC
 +      select ARCH_MXC_IOMUX_V3
 +      select ARCH_HAS_CPUFREQ
 +      select ARCH_MX5
 +      bool
 +
 +config SOC_IMX50
 +      bool
 +      select SOC_IMX5
 +      select ARCH_MX50
 +
 +config        SOC_IMX51
 +      bool
 +      select SOC_IMX5
 +      select ARCH_MX5
 +      select ARCH_MX51
 +
 +config        SOC_IMX53
 +      bool
 +      select SOC_IMX5
 +      select ARCH_MX5
 +      select ARCH_MX53
  
  if ARCH_IMX_V4_V5
  
@@@ -298,7 -261,6 +292,7 @@@ config MACH_MX27_3D
        select IMX_HAVE_PLATFORM_IMX_I2C
        select IMX_HAVE_PLATFORM_IMX_KEYPAD
        select IMX_HAVE_PLATFORM_IMX_UART
 +      select IMX_HAVE_PLATFORM_MX2_CAMERA
        select IMX_HAVE_PLATFORM_MXC_EHCI
        select IMX_HAVE_PLATFORM_MXC_MMC
        select IMX_HAVE_PLATFORM_SPI_IMX
@@@ -315,10 -277,8 +309,10 @@@ config MACH_IMX27_VISSTRIM_M1
        select IMX_HAVE_PLATFORM_IMX_I2C
        select IMX_HAVE_PLATFORM_IMX_SSI
        select IMX_HAVE_PLATFORM_IMX_UART
 -      select IMX_HAVE_PLATFORM_MXC_MMC
 +      select IMX_HAVE_PLATFORM_MX2_CAMERA
        select IMX_HAVE_PLATFORM_MXC_EHCI
 +      select IMX_HAVE_PLATFORM_MXC_MMC
 +      select LEDS_GPIO_REGISTER
        help
          Include support for Visstrim_m10 platform and its different variants.
          This includes specific configurations for the board and its
@@@ -373,14 -333,6 +367,14 @@@ config MACH_IMX27IPCA
          Include support for IMX27 IPCAM platform. This includes specific
          configurations for the board and its peripherals.
  
 +config MACH_IMX27_DT
 +      bool "Support i.MX27 platforms from device tree"
 +      select SOC_IMX27
 +      select USE_OF
 +      help
 +        Include support for Freescale i.MX27 based platforms
 +        using the device tree for discovery
 +
  endif
  
  if ARCH_IMX_V6_V7
@@@ -497,7 -449,6 +491,7 @@@ config MACH_MX31MOBOAR
        bool "Support mx31moboard platforms (EPFL Mobots group)"
        select SOC_IMX31
        select IMX_HAVE_PLATFORM_FSL_USB2_UDC
 +      select IMX_HAVE_PLATFORM_IMX2_WDT
        select IMX_HAVE_PLATFORM_IMX_I2C
        select IMX_HAVE_PLATFORM_IMX_UART
        select IMX_HAVE_PLATFORM_IPU_CORE
@@@ -635,207 -586,6 +629,207 @@@ config MACH_VPR20
          Include support for VPR200 platform. This includes specific
          configurations for the board and its peripherals.
  
 +comment "i.MX5 platforms:"
 +
 +config MACH_MX50_RDP
 +      bool "Support MX50 reference design platform"
 +      depends on BROKEN
 +      select SOC_IMX50
 +      select IMX_HAVE_PLATFORM_IMX_I2C
 +      select IMX_HAVE_PLATFORM_IMX_UART
 +      select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 +      select IMX_HAVE_PLATFORM_SPI_IMX
 +      help
 +        Include support for MX50 reference design platform (RDP) board. This
 +        includes specific configurations for the board and its peripherals.
 +
 +comment "i.MX51 machines:"
 +
 +config MACH_IMX51_DT
 +      bool "Support i.MX51 platforms from device tree"
 +      select SOC_IMX51
 +      select USE_OF
 +      select MACH_MX51_BABBAGE
 +      help
 +        Include support for Freescale i.MX51 based platforms
 +        using the device tree for discovery
 +
 +config MACH_MX51_BABBAGE
 +      bool "Support MX51 BABBAGE platforms"
 +      select SOC_IMX51
 +      select IMX_HAVE_PLATFORM_FSL_USB2_UDC
 +      select IMX_HAVE_PLATFORM_IMX2_WDT
 +      select IMX_HAVE_PLATFORM_IMX_I2C
 +      select IMX_HAVE_PLATFORM_IMX_UART
 +      select IMX_HAVE_PLATFORM_MXC_EHCI
 +      select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 +      select IMX_HAVE_PLATFORM_SPI_IMX
 +      help
 +        Include support for MX51 Babbage platform, also known as MX51EVK in
 +        u-boot. This includes specific configurations for the board and its
 +        peripherals.
 +
 +config MACH_MX51_3DS
 +      bool "Support MX51PDK (3DS)"
 +      select SOC_IMX51
 +      select IMX_HAVE_PLATFORM_IMX2_WDT
 +      select IMX_HAVE_PLATFORM_IMX_KEYPAD
 +      select IMX_HAVE_PLATFORM_IMX_UART
 +      select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 +      select IMX_HAVE_PLATFORM_SPI_IMX
 +      select MXC_DEBUG_BOARD
 +      help
 +        Include support for MX51PDK (3DS) platform. This includes specific
 +        configurations for the board and its peripherals.
 +
 +config MACH_EUKREA_CPUIMX51
 +      bool "Support Eukrea CPUIMX51 module"
 +      select SOC_IMX51
 +      select IMX_HAVE_PLATFORM_FSL_USB2_UDC
 +      select IMX_HAVE_PLATFORM_IMX_I2C
 +      select IMX_HAVE_PLATFORM_IMX_UART
 +      select IMX_HAVE_PLATFORM_MXC_EHCI
 +      select IMX_HAVE_PLATFORM_MXC_NAND
 +      select IMX_HAVE_PLATFORM_SPI_IMX
 +      help
 +        Include support for Eukrea CPUIMX51 platform. This includes
 +        specific configurations for the module and its peripherals.
 +
 +choice
 +      prompt "Baseboard"
 +      depends on MACH_EUKREA_CPUIMX51
 +      default MACH_EUKREA_MBIMX51_BASEBOARD
 +
 +config MACH_EUKREA_MBIMX51_BASEBOARD
 +      prompt "Eukrea MBIMX51 development board"
 +      bool
 +      select IMX_HAVE_PLATFORM_IMX_KEYPAD
 +      select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 +      select LEDS_GPIO_REGISTER
 +      help
 +        This adds board specific devices that can be found on Eukrea's
 +        MBIMX51 evaluation board.
 +
 +endchoice
 +
 +config MACH_EUKREA_CPUIMX51SD
 +      bool "Support Eukrea CPUIMX51SD module"
 +      select SOC_IMX51
 +      select IMX_HAVE_PLATFORM_FSL_USB2_UDC
 +      select IMX_HAVE_PLATFORM_IMX_I2C
 +      select IMX_HAVE_PLATFORM_IMX_UART
 +      select IMX_HAVE_PLATFORM_MXC_EHCI
 +      select IMX_HAVE_PLATFORM_MXC_NAND
 +      select IMX_HAVE_PLATFORM_SPI_IMX
 +      help
 +        Include support for Eukrea CPUIMX51SD platform. This includes
 +        specific configurations for the module and its peripherals.
 +
 +choice
 +      prompt "Baseboard"
 +      depends on MACH_EUKREA_CPUIMX51SD
 +      default MACH_EUKREA_MBIMXSD51_BASEBOARD
 +
 +config MACH_EUKREA_MBIMXSD51_BASEBOARD
 +      prompt "Eukrea MBIMXSD development board"
 +      bool
 +      select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 +      select LEDS_GPIO_REGISTER
 +      help
 +        This adds board specific devices that can be found on Eukrea's
 +        MBIMXSD evaluation board.
 +
 +endchoice
 +
 +config MX51_EFIKA_COMMON
 +      bool
 +      select SOC_IMX51
 +      select IMX_HAVE_PLATFORM_IMX_UART
 +      select IMX_HAVE_PLATFORM_MXC_EHCI
 +      select IMX_HAVE_PLATFORM_PATA_IMX
 +      select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 +      select IMX_HAVE_PLATFORM_SPI_IMX
 +      select MXC_ULPI if USB_ULPI
 +
 +config MACH_MX51_EFIKAMX
 +      bool "Support MX51 Genesi Efika MX nettop"
 +      select LEDS_GPIO_REGISTER
 +      select MX51_EFIKA_COMMON
 +      help
 +        Include support for Genesi Efika MX nettop. This includes specific
 +        configurations for the board and its peripherals.
 +
 +config MACH_MX51_EFIKASB
 +      bool "Support MX51 Genesi Efika Smartbook"
 +      select LEDS_GPIO_REGISTER
 +      select MX51_EFIKA_COMMON
 +      help
 +        Include support for Genesi Efika Smartbook. This includes specific
 +        configurations for the board and its peripherals.
 +
 +comment "i.MX53 machines:"
 +
 +config MACH_IMX53_DT
 +      bool "Support i.MX53 platforms from device tree"
 +      select SOC_IMX53
 +      select USE_OF
 +      select MACH_MX53_ARD
 +      select MACH_MX53_EVK
 +      select MACH_MX53_LOCO
 +      select MACH_MX53_SMD
 +      help
 +        Include support for Freescale i.MX53 based platforms
 +        using the device tree for discovery
 +
 +config MACH_MX53_EVK
 +      bool "Support MX53 EVK platforms"
 +      select SOC_IMX53
 +      select IMX_HAVE_PLATFORM_IMX2_WDT
 +      select IMX_HAVE_PLATFORM_IMX_UART
 +      select IMX_HAVE_PLATFORM_IMX_I2C
 +      select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 +      select IMX_HAVE_PLATFORM_SPI_IMX
 +      select LEDS_GPIO_REGISTER
 +      help
 +        Include support for MX53 EVK platform. This includes specific
 +        configurations for the board and its peripherals.
 +
 +config MACH_MX53_SMD
 +      bool "Support MX53 SMD platforms"
 +      select SOC_IMX53
 +      select IMX_HAVE_PLATFORM_IMX2_WDT
 +      select IMX_HAVE_PLATFORM_IMX_I2C
 +      select IMX_HAVE_PLATFORM_IMX_UART
 +      select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 +      help
 +        Include support for MX53 SMD platform. This includes specific
 +        configurations for the board and its peripherals.
 +
 +config MACH_MX53_LOCO
 +      bool "Support MX53 LOCO platforms"
 +      select SOC_IMX53
 +      select IMX_HAVE_PLATFORM_IMX2_WDT
 +      select IMX_HAVE_PLATFORM_IMX_I2C
 +      select IMX_HAVE_PLATFORM_IMX_UART
 +      select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 +      select IMX_HAVE_PLATFORM_GPIO_KEYS
 +      select LEDS_GPIO_REGISTER
 +      help
 +        Include support for MX53 LOCO platform. This includes specific
 +        configurations for the board and its peripherals.
 +
 +config MACH_MX53_ARD
 +      bool "Support MX53 ARD platforms"
 +      select SOC_IMX53
 +      select IMX_HAVE_PLATFORM_IMX2_WDT
 +      select IMX_HAVE_PLATFORM_IMX_I2C
 +      select IMX_HAVE_PLATFORM_IMX_UART
 +      select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 +      select IMX_HAVE_PLATFORM_GPIO_KEYS
 +      help
 +        Include support for MX53 ARD platform. This includes specific
 +        configurations for the board and its peripherals.
 +
  comment "i.MX6 family:"
  
  config SOC_IMX6Q
index 35fc450fa263c2eb1e3d08d4bccd2c389e9b2105,a62dc3ac9dc60487ef6f8c03525373f20371026a..ab939c5046c37080692a37592944ccfa7a2c4100
@@@ -1,5 -1,3 +1,3 @@@
- obj-$(CONFIG_IMX_HAVE_DMA_V1) += dma-v1.o
  obj-$(CONFIG_SOC_IMX1) += clock-imx1.o mm-imx1.o
  obj-$(CONFIG_SOC_IMX21) += clock-imx21.o mm-imx21.o
  
@@@ -8,10 -6,8 +6,10 @@@ obj-$(CONFIG_SOC_IMX25) += clock-imx25.
  obj-$(CONFIG_SOC_IMX27) += cpu-imx27.o pm-imx27.o
  obj-$(CONFIG_SOC_IMX27) += clock-imx27.o mm-imx27.o ehci-imx27.o
  
 -obj-$(CONFIG_SOC_IMX31) += mm-imx3.o cpu-imx31.o clock-imx31.o iomux-imx31.o ehci-imx31.o
 -obj-$(CONFIG_SOC_IMX35) += mm-imx3.o cpu-imx35.o clock-imx35.o ehci-imx35.o
 +obj-$(CONFIG_SOC_IMX31) += mm-imx3.o cpu-imx31.o clock-imx31.o iomux-imx31.o ehci-imx31.o pm-imx3.o
 +obj-$(CONFIG_SOC_IMX35) += mm-imx3.o cpu-imx35.o clock-imx35.o ehci-imx35.o pm-imx3.o
 +
 +obj-$(CONFIG_SOC_IMX5) += cpu-imx5.o mm-imx5.o clock-mx51-mx53.o ehci-imx5.o pm-imx5.o cpu_op-mx51.o
  
  # Support for CMOS sensor interface
  obj-$(CONFIG_MX1_VIDEO) += mx1-camera-fiq.o mx1-camera-fiq-ksym.o
@@@ -41,7 -37,6 +39,7 @@@ obj-$(CONFIG_MACH_EUKREA_MBIMX27_BASEBO
  obj-$(CONFIG_MACH_PCA100) += mach-pca100.o
  obj-$(CONFIG_MACH_MXT_TD60) += mach-mxt_td60.o
  obj-$(CONFIG_MACH_IMX27IPCAM) += mach-imx27ipcam.o
 +obj-$(CONFIG_MACH_IMX27_DT) += imx27-dt.o
  
  # i.MX31 based machines
  obj-$(CONFIG_MACH_MX31ADS) += mach-mx31ads.o
@@@ -72,27 -67,9 +70,27 @@@ obj-$(CONFIG_CPU_V7) += head-v7.
  AFLAGS_head-v7.o :=-Wa,-march=armv7-a
  obj-$(CONFIG_SMP) += platsmp.o
  obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
 -obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o
  obj-$(CONFIG_SOC_IMX6Q) += clock-imx6q.o mach-imx6q.o
  
  ifeq ($(CONFIG_PM),y)
  obj-$(CONFIG_SOC_IMX6Q) += pm-imx6q.o
  endif
 +
 +# i.MX5 based machines
 +obj-$(CONFIG_MACH_MX51_BABBAGE) += mach-mx51_babbage.o
 +obj-$(CONFIG_MACH_MX51_3DS) += mach-mx51_3ds.o
 +obj-$(CONFIG_MACH_MX53_EVK) += mach-mx53_evk.o
 +obj-$(CONFIG_MACH_MX53_SMD) += mach-mx53_smd.o
 +obj-$(CONFIG_MACH_MX53_LOCO) += mach-mx53_loco.o
 +obj-$(CONFIG_MACH_MX53_ARD) += mach-mx53_ard.o
 +obj-$(CONFIG_MACH_EUKREA_CPUIMX51) += mach-cpuimx51.o
 +obj-$(CONFIG_MACH_EUKREA_MBIMX51_BASEBOARD) += eukrea_mbimx51-baseboard.o
 +obj-$(CONFIG_MACH_EUKREA_CPUIMX51SD) += mach-cpuimx51sd.o
 +obj-$(CONFIG_MACH_EUKREA_MBIMXSD51_BASEBOARD) += eukrea_mbimxsd-baseboard.o
 +obj-$(CONFIG_MX51_EFIKA_COMMON) += mx51_efika.o
 +obj-$(CONFIG_MACH_MX51_EFIKAMX) += mach-mx51_efikamx.o
 +obj-$(CONFIG_MACH_MX51_EFIKASB) += mach-mx51_efikasb.o
 +obj-$(CONFIG_MACH_MX50_RDP) += mach-mx50_rdp.o
 +
 +obj-$(CONFIG_MACH_IMX51_DT) += imx51-dt.o
 +obj-$(CONFIG_MACH_IMX53_DT) += imx53-dt.o
index 301d9c319d0bb69b590eb63cc5e4b2319a466cb1,a6ef3961134ce668df966493e9bf31edd6138b31..eb9f4f5340060d432f7fd6741a3acfc6fbfa2dbc
@@@ -79,11 -79,11 +79,11 @@@ static int samsung_dmadev_prepare(unsig
                            info->len, offset_in_page(info->buf));
                sg_dma_address(&sg) = info->buf;
  
-               desc = chan->device->device_prep_slave_sg(chan,
+               desc = dmaengine_prep_slave_sg(chan,
                        &sg, 1, info->direction, DMA_PREP_INTERRUPT);
                break;
        case DMA_CYCLIC:
-               desc = chan->device->device_prep_dma_cyclic(chan,
+               desc = dmaengine_prep_dma_cyclic(chan,
                        info->buf, info->len, info->period, info->direction);
                break;
        default:
@@@ -116,7 -116,7 +116,7 @@@ static inline int samsung_dmadev_flush(
        return dmaengine_terminate_all((struct dma_chan *)ch);
  }
  
 -struct samsung_dma_ops dmadev_ops = {
 +static struct samsung_dma_ops dmadev_ops = {
        .request        = samsung_dmadev_request,
        .release        = samsung_dmadev_release,
        .prepare        = samsung_dmadev_prepare,
index 889c544688ca020c4d99f1b3e5d989c8f002308d,43c44e77d83c8ba265350b73cfc95efc7148c850..0445c4fd67e311e864cf6f9d8e70f4ef3bb530f6
@@@ -1055,6 -1055,8 +1055,6 @@@ struct platform_device *__init at32_add
        return at32_usarts[id];
  }
  
 -struct platform_device *atmel_default_console_device;
 -
  void __init at32_setup_serial_console(unsigned int usart_id)
  {
        atmel_default_console_device = at32_usarts[usart_id];
@@@ -1351,7 -1353,6 +1351,6 @@@ at32_add_device_mci(unsigned int id, st
                goto fail;
  
        slave->sdata.dma_dev = &dw_dmac0_device.dev;
-       slave->sdata.reg_width = DW_DMA_SLAVE_WIDTH_32BIT;
        slave->sdata.cfg_hi = (DWC_CFGH_SRC_PER(0)
                                | DWC_CFGH_DST_PER(1));
        slave->sdata.cfg_lo &= ~(DWC_CFGL_HS_DST_POL
@@@ -2046,27 -2047,19 +2045,19 @@@ at32_add_device_ac97c(unsigned int id, 
        /* Check if DMA slave interface for capture should be configured. */
        if (flags & AC97C_CAPTURE) {
                rx_dws->dma_dev = &dw_dmac0_device.dev;
-               rx_dws->reg_width = DW_DMA_SLAVE_WIDTH_16BIT;
                rx_dws->cfg_hi = DWC_CFGH_SRC_PER(3);
                rx_dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL);
                rx_dws->src_master = 0;
                rx_dws->dst_master = 1;
-               rx_dws->src_msize = DW_DMA_MSIZE_1;
-               rx_dws->dst_msize = DW_DMA_MSIZE_1;
-               rx_dws->fc = DW_DMA_FC_D_P2M;
        }
  
        /* Check if DMA slave interface for playback should be configured. */
        if (flags & AC97C_PLAYBACK) {
                tx_dws->dma_dev = &dw_dmac0_device.dev;
-               tx_dws->reg_width = DW_DMA_SLAVE_WIDTH_16BIT;
                tx_dws->cfg_hi = DWC_CFGH_DST_PER(4);
                tx_dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL);
                tx_dws->src_master = 0;
                tx_dws->dst_master = 1;
-               tx_dws->src_msize = DW_DMA_MSIZE_1;
-               tx_dws->dst_msize = DW_DMA_MSIZE_1;
-               tx_dws->fc = DW_DMA_FC_D_M2P;
        }
  
        if (platform_device_add_data(pdev, data,
@@@ -2136,14 -2129,10 +2127,10 @@@ at32_add_device_abdac(unsigned int id, 
        dws = &data->dws;
  
        dws->dma_dev = &dw_dmac0_device.dev;
-       dws->reg_width = DW_DMA_SLAVE_WIDTH_32BIT;
        dws->cfg_hi = DWC_CFGH_DST_PER(2);
        dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL);
        dws->src_master = 0;
        dws->dst_master = 1;
-       dws->src_msize = DW_DMA_MSIZE_1;
-       dws->dst_msize = DW_DMA_MSIZE_1;
-       dws->fc = DW_DMA_FC_D_M2P;
  
        if (platform_device_add_data(pdev, data,
                                sizeof(struct atmel_abdac_pdata)))
diff --combined drivers/dma/Kconfig
index 4a6c46dea8a0c3c7741613576b5d9f180a2058c7,34e48d905c27047c9edcfdb300c0e8904043d1b7..cf9da362d64f9a233512ce7a228bccad25906197
@@@ -201,7 -201,6 +201,6 @@@ config PL330_DM
        tristate "DMA API Driver for PL330"
        select DMA_ENGINE
        depends on ARM_AMBA
-       select PL330
        help
          Select if your platform has one or more PL330 DMACs.
          You need to provide platform specific settings via
@@@ -231,7 -230,7 +230,7 @@@ config IMX_SDM
  
  config IMX_DMA
        tristate "i.MX DMA support"
-       depends on IMX_HAVE_DMA_V1
+       depends on ARCH_MXC
        select DMA_ENGINE
        help
          Support the i.MX DMA engine. This engine is integrated into
@@@ -252,15 -251,6 +251,15 @@@ config EP93XX_DM
        help
          Enable support for the Cirrus Logic EP93xx M2P/M2M DMA controller.
  
 +config DMA_SA11X0
 +      tristate "SA-11x0 DMA support"
 +      depends on ARCH_SA1100
 +      select DMA_ENGINE
 +      help
 +        Support the DMA engine found on Intel StrongARM SA-1100 and
 +        SA-1110 SoCs.  This DMA engine can only be used with on-chip
 +        devices.
 +
  config DMA_ENGINE
        bool
  
diff --combined drivers/dma/imx-dma.c
index 38586ba8da91fd4c63478670cff28ddf3ce14247,569b0a29fa8c19d4d35e95473c2187d3f1f56acd..a45b5d2a59879a02b3566dfaf2c8304f8d693921
@@@ -5,6 -5,7 +5,7 @@@
   * found on i.MX1/21/27
   *
   * Copyright 2010 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
+  * Copyright 2012 Javier Martin, Vista Silicon <javier.martin@vista-silicon.com>
   *
   * The code contained herein is licensed under the GNU General Public
   * License. You may obtain a copy of the GNU General Public License
@@@ -14,6 -15,7 +15,6 @@@
   * http://www.gnu.org/copyleft/gpl.html
   */
  #include <linux/init.h>
 -#include <linux/module.h>
  #include <linux/types.h>
  #include <linux/mm.h>
  #include <linux/interrupt.h>
  #include <linux/dma-mapping.h>
  #include <linux/slab.h>
  #include <linux/platform_device.h>
+ #include <linux/clk.h>
  #include <linux/dmaengine.h>
  #include <linux/module.h>
  
  #include <asm/irq.h>
- #include <mach/dma-v1.h>
+ #include <mach/dma.h>
  #include <mach/hardware.h>
  
+ #include "dmaengine.h"
+ #define IMXDMA_MAX_CHAN_DESCRIPTORS   16
+ #define IMX_DMA_CHANNELS  16
+ #define IMX_DMA_2D_SLOTS      2
+ #define IMX_DMA_2D_SLOT_A     0
+ #define IMX_DMA_2D_SLOT_B     1
+ #define IMX_DMA_LENGTH_LOOP   ((unsigned int)-1)
+ #define IMX_DMA_MEMSIZE_32    (0 << 4)
+ #define IMX_DMA_MEMSIZE_8     (1 << 4)
+ #define IMX_DMA_MEMSIZE_16    (2 << 4)
+ #define IMX_DMA_TYPE_LINEAR   (0 << 10)
+ #define IMX_DMA_TYPE_2D               (1 << 10)
+ #define IMX_DMA_TYPE_FIFO     (2 << 10)
+ #define IMX_DMA_ERR_BURST     (1 << 0)
+ #define IMX_DMA_ERR_REQUEST   (1 << 1)
+ #define IMX_DMA_ERR_TRANSFER  (1 << 2)
+ #define IMX_DMA_ERR_BUFFER    (1 << 3)
+ #define IMX_DMA_ERR_TIMEOUT   (1 << 4)
+ #define DMA_DCR     0x00              /* Control Register */
+ #define DMA_DISR    0x04              /* Interrupt status Register */
+ #define DMA_DIMR    0x08              /* Interrupt mask Register */
+ #define DMA_DBTOSR  0x0c              /* Burst timeout status Register */
+ #define DMA_DRTOSR  0x10              /* Request timeout Register */
+ #define DMA_DSESR   0x14              /* Transfer Error Status Register */
+ #define DMA_DBOSR   0x18              /* Buffer overflow status Register */
+ #define DMA_DBTOCR  0x1c              /* Burst timeout control Register */
+ #define DMA_WSRA    0x40              /* W-Size Register A */
+ #define DMA_XSRA    0x44              /* X-Size Register A */
+ #define DMA_YSRA    0x48              /* Y-Size Register A */
+ #define DMA_WSRB    0x4c              /* W-Size Register B */
+ #define DMA_XSRB    0x50              /* X-Size Register B */
+ #define DMA_YSRB    0x54              /* Y-Size Register B */
+ #define DMA_SAR(x)  (0x80 + ((x) << 6))       /* Source Address Registers */
+ #define DMA_DAR(x)  (0x84 + ((x) << 6))       /* Destination Address Registers */
+ #define DMA_CNTR(x) (0x88 + ((x) << 6))       /* Count Registers */
+ #define DMA_CCR(x)  (0x8c + ((x) << 6))       /* Control Registers */
+ #define DMA_RSSR(x) (0x90 + ((x) << 6))       /* Request source select Registers */
+ #define DMA_BLR(x)  (0x94 + ((x) << 6))       /* Burst length Registers */
+ #define DMA_RTOR(x) (0x98 + ((x) << 6))       /* Request timeout Registers */
+ #define DMA_BUCR(x) (0x98 + ((x) << 6))       /* Bus Utilization Registers */
+ #define DMA_CCNR(x) (0x9C + ((x) << 6))       /* Channel counter Registers */
+ #define DCR_DRST           (1<<1)
+ #define DCR_DEN            (1<<0)
+ #define DBTOCR_EN          (1<<15)
+ #define DBTOCR_CNT(x)      ((x) & 0x7fff)
+ #define CNTR_CNT(x)        ((x) & 0xffffff)
+ #define CCR_ACRPT          (1<<14)
+ #define CCR_DMOD_LINEAR    (0x0 << 12)
+ #define CCR_DMOD_2D        (0x1 << 12)
+ #define CCR_DMOD_FIFO      (0x2 << 12)
+ #define CCR_DMOD_EOBFIFO   (0x3 << 12)
+ #define CCR_SMOD_LINEAR    (0x0 << 10)
+ #define CCR_SMOD_2D        (0x1 << 10)
+ #define CCR_SMOD_FIFO      (0x2 << 10)
+ #define CCR_SMOD_EOBFIFO   (0x3 << 10)
+ #define CCR_MDIR_DEC       (1<<9)
+ #define CCR_MSEL_B         (1<<8)
+ #define CCR_DSIZ_32        (0x0 << 6)
+ #define CCR_DSIZ_8         (0x1 << 6)
+ #define CCR_DSIZ_16        (0x2 << 6)
+ #define CCR_SSIZ_32        (0x0 << 4)
+ #define CCR_SSIZ_8         (0x1 << 4)
+ #define CCR_SSIZ_16        (0x2 << 4)
+ #define CCR_REN            (1<<3)
+ #define CCR_RPT            (1<<2)
+ #define CCR_FRC            (1<<1)
+ #define CCR_CEN            (1<<0)
+ #define RTOR_EN            (1<<15)
+ #define RTOR_CLK           (1<<14)
+ #define RTOR_PSC           (1<<13)
+ enum  imxdma_prep_type {
+       IMXDMA_DESC_MEMCPY,
+       IMXDMA_DESC_INTERLEAVED,
+       IMXDMA_DESC_SLAVE_SG,
+       IMXDMA_DESC_CYCLIC,
+ };
+ struct imx_dma_2d_config {
+       u16             xsr;
+       u16             ysr;
+       u16             wsr;
+       int             count;
+ };
+ struct imxdma_desc {
+       struct list_head                node;
+       struct dma_async_tx_descriptor  desc;
+       enum dma_status                 status;
+       dma_addr_t                      src;
+       dma_addr_t                      dest;
+       size_t                          len;
+       enum dma_transfer_direction     direction;
+       enum imxdma_prep_type           type;
+       /* For memcpy and interleaved */
+       unsigned int                    config_port;
+       unsigned int                    config_mem;
+       /* For interleaved transfers */
+       unsigned int                    x;
+       unsigned int                    y;
+       unsigned int                    w;
+       /* For slave sg and cyclic */
+       struct scatterlist              *sg;
+       unsigned int                    sgcount;
+ };
  struct imxdma_channel {
+       int                             hw_chaining;
+       struct timer_list               watchdog;
        struct imxdma_engine            *imxdma;
        unsigned int                    channel;
-       unsigned int                    imxdma_channel;
  
+       struct tasklet_struct           dma_tasklet;
+       struct list_head                ld_free;
+       struct list_head                ld_queue;
+       struct list_head                ld_active;
+       int                             descs_allocated;
        enum dma_slave_buswidth         word_size;
        dma_addr_t                      per_address;
        u32                             watermark_level;
        struct dma_chan                 chan;
-       spinlock_t                      lock;
        struct dma_async_tx_descriptor  desc;
-       dma_cookie_t                    last_completed;
        enum dma_status                 status;
        int                             dma_request;
        struct scatterlist              *sg_list;
+       u32                             ccr_from_device;
+       u32                             ccr_to_device;
+       bool                            enabled_2d;
+       int                             slot_2d;
  };
  
- #define MAX_DMA_CHANNELS 8
  struct imxdma_engine {
        struct device                   *dev;
        struct device_dma_parameters    dma_parms;
        struct dma_device               dma_device;
-       struct imxdma_channel           channel[MAX_DMA_CHANNELS];
+       void __iomem                    *base;
+       struct clk                      *dma_clk;
+       spinlock_t                      lock;
+       struct imx_dma_2d_config        slots_2d[IMX_DMA_2D_SLOTS];
+       struct imxdma_channel           channel[IMX_DMA_CHANNELS];
  };
  
  static struct imxdma_channel *to_imxdma_chan(struct dma_chan *chan)
        return container_of(chan, struct imxdma_channel, chan);
  }
  
- static void imxdma_handle(struct imxdma_channel *imxdmac)
+ static inline bool imxdma_chan_is_doing_cyclic(struct imxdma_channel *imxdmac)
+ {
+       struct imxdma_desc *desc;
+       if (!list_empty(&imxdmac->ld_active)) {
+               desc = list_first_entry(&imxdmac->ld_active, struct imxdma_desc,
+                                       node);
+               if (desc->type == IMXDMA_DESC_CYCLIC)
+                       return true;
+       }
+       return false;
+ }
+ static void imx_dmav1_writel(struct imxdma_engine *imxdma, unsigned val,
+                            unsigned offset)
+ {
+       __raw_writel(val, imxdma->base + offset);
+ }
+ static unsigned imx_dmav1_readl(struct imxdma_engine *imxdma, unsigned offset)
+ {
+       return __raw_readl(imxdma->base + offset);
+ }
+ static int imxdma_hw_chain(struct imxdma_channel *imxdmac)
+ {
+       if (cpu_is_mx27())
+               return imxdmac->hw_chaining;
+       else
+               return 0;
+ }
+ /*
+  * imxdma_sg_next - prepare next chunk for scatter-gather DMA emulation
+  */
+ static inline int imxdma_sg_next(struct imxdma_desc *d)
  {
-       if (imxdmac->desc.callback)
-               imxdmac->desc.callback(imxdmac->desc.callback_param);
-       imxdmac->last_completed = imxdmac->desc.cookie;
+       struct imxdma_channel *imxdmac = to_imxdma_chan(d->desc.chan);
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       struct scatterlist *sg = d->sg;
+       unsigned long now;
+       now = min(d->len, sg->length);
+       if (d->len != IMX_DMA_LENGTH_LOOP)
+               d->len -= now;
+       if (d->direction == DMA_DEV_TO_MEM)
+               imx_dmav1_writel(imxdma, sg->dma_address,
+                                DMA_DAR(imxdmac->channel));
+       else
+               imx_dmav1_writel(imxdma, sg->dma_address,
+                                DMA_SAR(imxdmac->channel));
+       imx_dmav1_writel(imxdma, now, DMA_CNTR(imxdmac->channel));
+       dev_dbg(imxdma->dev, " %s channel: %d dst 0x%08x, src 0x%08x, "
+               "size 0x%08x\n", __func__, imxdmac->channel,
+                imx_dmav1_readl(imxdma, DMA_DAR(imxdmac->channel)),
+                imx_dmav1_readl(imxdma, DMA_SAR(imxdmac->channel)),
+                imx_dmav1_readl(imxdma, DMA_CNTR(imxdmac->channel)));
+       return now;
  }
  
- static void imxdma_irq_handler(int channel, void *data)
+ static void imxdma_enable_hw(struct imxdma_desc *d)
  {
-       struct imxdma_channel *imxdmac = data;
+       struct imxdma_channel *imxdmac = to_imxdma_chan(d->desc.chan);
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       int channel = imxdmac->channel;
+       unsigned long flags;
+       dev_dbg(imxdma->dev, "%s channel %d\n", __func__, channel);
+       local_irq_save(flags);
+       imx_dmav1_writel(imxdma, 1 << channel, DMA_DISR);
+       imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_DIMR) &
+                        ~(1 << channel), DMA_DIMR);
+       imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_CCR(channel)) |
+                        CCR_CEN | CCR_ACRPT, DMA_CCR(channel));
+       if ((cpu_is_mx21() || cpu_is_mx27()) &&
+                       d->sg && imxdma_hw_chain(imxdmac)) {
+               d->sg = sg_next(d->sg);
+               if (d->sg) {
+                       u32 tmp;
+                       imxdma_sg_next(d);
+                       tmp = imx_dmav1_readl(imxdma, DMA_CCR(channel));
+                       imx_dmav1_writel(imxdma, tmp | CCR_RPT | CCR_ACRPT,
+                                        DMA_CCR(channel));
+               }
+       }
+       local_irq_restore(flags);
+ }
+ static void imxdma_disable_hw(struct imxdma_channel *imxdmac)
+ {
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       int channel = imxdmac->channel;
+       unsigned long flags;
+       dev_dbg(imxdma->dev, "%s channel %d\n", __func__, channel);
+       if (imxdma_hw_chain(imxdmac))
+               del_timer(&imxdmac->watchdog);
+       local_irq_save(flags);
+       imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_DIMR) |
+                        (1 << channel), DMA_DIMR);
+       imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_CCR(channel)) &
+                        ~CCR_CEN, DMA_CCR(channel));
+       imx_dmav1_writel(imxdma, 1 << channel, DMA_DISR);
+       local_irq_restore(flags);
+ }
+ static void imxdma_watchdog(unsigned long data)
+ {
+       struct imxdma_channel *imxdmac = (struct imxdma_channel *)data;
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       int channel = imxdmac->channel;
+       imx_dmav1_writel(imxdma, 0, DMA_CCR(channel));
  
-       imxdmac->status = DMA_SUCCESS;
-       imxdma_handle(imxdmac);
+       /* Tasklet watchdog error handler */
+       tasklet_schedule(&imxdmac->dma_tasklet);
+       dev_dbg(imxdma->dev, "channel %d: watchdog timeout!\n",
+               imxdmac->channel);
  }
  
- static void imxdma_err_handler(int channel, void *data, int error)
+ static irqreturn_t imxdma_err_handler(int irq, void *dev_id)
  {
-       struct imxdma_channel *imxdmac = data;
+       struct imxdma_engine *imxdma = dev_id;
+       unsigned int err_mask;
+       int i, disr;
+       int errcode;
+       disr = imx_dmav1_readl(imxdma, DMA_DISR);
+       err_mask = imx_dmav1_readl(imxdma, DMA_DBTOSR) |
+                  imx_dmav1_readl(imxdma, DMA_DRTOSR) |
+                  imx_dmav1_readl(imxdma, DMA_DSESR)  |
+                  imx_dmav1_readl(imxdma, DMA_DBOSR);
+       if (!err_mask)
+               return IRQ_HANDLED;
+       imx_dmav1_writel(imxdma, disr & err_mask, DMA_DISR);
+       for (i = 0; i < IMX_DMA_CHANNELS; i++) {
+               if (!(err_mask & (1 << i)))
+                       continue;
+               errcode = 0;
+               if (imx_dmav1_readl(imxdma, DMA_DBTOSR) & (1 << i)) {
+                       imx_dmav1_writel(imxdma, 1 << i, DMA_DBTOSR);
+                       errcode |= IMX_DMA_ERR_BURST;
+               }
+               if (imx_dmav1_readl(imxdma, DMA_DRTOSR) & (1 << i)) {
+                       imx_dmav1_writel(imxdma, 1 << i, DMA_DRTOSR);
+                       errcode |= IMX_DMA_ERR_REQUEST;
+               }
+               if (imx_dmav1_readl(imxdma, DMA_DSESR) & (1 << i)) {
+                       imx_dmav1_writel(imxdma, 1 << i, DMA_DSESR);
+                       errcode |= IMX_DMA_ERR_TRANSFER;
+               }
+               if (imx_dmav1_readl(imxdma, DMA_DBOSR) & (1 << i)) {
+                       imx_dmav1_writel(imxdma, 1 << i, DMA_DBOSR);
+                       errcode |= IMX_DMA_ERR_BUFFER;
+               }
+               /* Tasklet error handler */
+               tasklet_schedule(&imxdma->channel[i].dma_tasklet);
+               printk(KERN_WARNING
+                      "DMA timeout on channel %d -%s%s%s%s\n", i,
+                      errcode & IMX_DMA_ERR_BURST ?    " burst" : "",
+                      errcode & IMX_DMA_ERR_REQUEST ?  " request" : "",
+                      errcode & IMX_DMA_ERR_TRANSFER ? " transfer" : "",
+                      errcode & IMX_DMA_ERR_BUFFER ?   " buffer" : "");
+       }
+       return IRQ_HANDLED;
+ }
+ static void dma_irq_handle_channel(struct imxdma_channel *imxdmac)
+ {
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       int chno = imxdmac->channel;
+       struct imxdma_desc *desc;
+       spin_lock(&imxdma->lock);
+       if (list_empty(&imxdmac->ld_active)) {
+               spin_unlock(&imxdma->lock);
+               goto out;
+       }
+       desc = list_first_entry(&imxdmac->ld_active,
+                               struct imxdma_desc,
+                               node);
+       spin_unlock(&imxdma->lock);
+       if (desc->sg) {
+               u32 tmp;
+               desc->sg = sg_next(desc->sg);
+               if (desc->sg) {
+                       imxdma_sg_next(desc);
+                       tmp = imx_dmav1_readl(imxdma, DMA_CCR(chno));
+                       if (imxdma_hw_chain(imxdmac)) {
+                               /* FIXME: The timeout should probably be
+                                * configurable
+                                */
+                               mod_timer(&imxdmac->watchdog,
+                                       jiffies + msecs_to_jiffies(500));
+                               tmp |= CCR_CEN | CCR_RPT | CCR_ACRPT;
+                               imx_dmav1_writel(imxdma, tmp, DMA_CCR(chno));
+                       } else {
+                               imx_dmav1_writel(imxdma, tmp & ~CCR_CEN,
+                                                DMA_CCR(chno));
+                               tmp |= CCR_CEN;
+                       }
+                       imx_dmav1_writel(imxdma, tmp, DMA_CCR(chno));
+                       if (imxdma_chan_is_doing_cyclic(imxdmac))
+                               /* Tasklet progression */
+                               tasklet_schedule(&imxdmac->dma_tasklet);
+                       return;
+               }
+               if (imxdma_hw_chain(imxdmac)) {
+                       del_timer(&imxdmac->watchdog);
+                       return;
+               }
+       }
+ out:
+       imx_dmav1_writel(imxdma, 0, DMA_CCR(chno));
+       /* Tasklet irq */
+       tasklet_schedule(&imxdmac->dma_tasklet);
+ }
+ static irqreturn_t dma_irq_handler(int irq, void *dev_id)
+ {
+       struct imxdma_engine *imxdma = dev_id;
+       int i, disr;
+       if (cpu_is_mx21() || cpu_is_mx27())
+               imxdma_err_handler(irq, dev_id);
+       disr = imx_dmav1_readl(imxdma, DMA_DISR);
+       dev_dbg(imxdma->dev, "%s called, disr=0x%08x\n", __func__, disr);
+       imx_dmav1_writel(imxdma, disr, DMA_DISR);
+       for (i = 0; i < IMX_DMA_CHANNELS; i++) {
+               if (disr & (1 << i))
+                       dma_irq_handle_channel(&imxdma->channel[i]);
+       }
+       return IRQ_HANDLED;
+ }
+ static int imxdma_xfer_desc(struct imxdma_desc *d)
+ {
+       struct imxdma_channel *imxdmac = to_imxdma_chan(d->desc.chan);
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       unsigned long flags;
+       int slot = -1;
+       int i;
+       /* Configure and enable */
+       switch (d->type) {
+       case IMXDMA_DESC_INTERLEAVED:
+               /* Try to get a free 2D slot */
+               spin_lock_irqsave(&imxdma->lock, flags);
+               for (i = 0; i < IMX_DMA_2D_SLOTS; i++) {
+                       if ((imxdma->slots_2d[i].count > 0) &&
+                       ((imxdma->slots_2d[i].xsr != d->x) ||
+                       (imxdma->slots_2d[i].ysr != d->y) ||
+                       (imxdma->slots_2d[i].wsr != d->w)))
+                               continue;
+                       slot = i;
+                       break;
+               }
+               if (slot < 0)
+                       return -EBUSY;
+               imxdma->slots_2d[slot].xsr = d->x;
+               imxdma->slots_2d[slot].ysr = d->y;
+               imxdma->slots_2d[slot].wsr = d->w;
+               imxdma->slots_2d[slot].count++;
+               imxdmac->slot_2d = slot;
+               imxdmac->enabled_2d = true;
+               spin_unlock_irqrestore(&imxdma->lock, flags);
+               if (slot == IMX_DMA_2D_SLOT_A) {
+                       d->config_mem &= ~CCR_MSEL_B;
+                       d->config_port &= ~CCR_MSEL_B;
+                       imx_dmav1_writel(imxdma, d->x, DMA_XSRA);
+                       imx_dmav1_writel(imxdma, d->y, DMA_YSRA);
+                       imx_dmav1_writel(imxdma, d->w, DMA_WSRA);
+               } else {
+                       d->config_mem |= CCR_MSEL_B;
+                       d->config_port |= CCR_MSEL_B;
+                       imx_dmav1_writel(imxdma, d->x, DMA_XSRB);
+                       imx_dmav1_writel(imxdma, d->y, DMA_YSRB);
+                       imx_dmav1_writel(imxdma, d->w, DMA_WSRB);
+               }
+               /*
+                * We fall-through here intentionally, since a 2D transfer is
+                * similar to MEMCPY just adding the 2D slot configuration.
+                */
+       case IMXDMA_DESC_MEMCPY:
+               imx_dmav1_writel(imxdma, d->src, DMA_SAR(imxdmac->channel));
+               imx_dmav1_writel(imxdma, d->dest, DMA_DAR(imxdmac->channel));
+               imx_dmav1_writel(imxdma, d->config_mem | (d->config_port << 2),
+                        DMA_CCR(imxdmac->channel));
+               imx_dmav1_writel(imxdma, d->len, DMA_CNTR(imxdmac->channel));
+               dev_dbg(imxdma->dev, "%s channel: %d dest=0x%08x src=0x%08x "
+                       "dma_length=%d\n", __func__, imxdmac->channel,
+                       d->dest, d->src, d->len);
+               break;
+       /* Cyclic transfer is the same as slave_sg with special sg configuration. */
+       case IMXDMA_DESC_CYCLIC:
+       case IMXDMA_DESC_SLAVE_SG:
+               if (d->direction == DMA_DEV_TO_MEM) {
+                       imx_dmav1_writel(imxdma, imxdmac->per_address,
+                                        DMA_SAR(imxdmac->channel));
+                       imx_dmav1_writel(imxdma, imxdmac->ccr_from_device,
+                                        DMA_CCR(imxdmac->channel));
+                       dev_dbg(imxdma->dev, "%s channel: %d sg=%p sgcount=%d "
+                               "total length=%d dev_addr=0x%08x (dev2mem)\n",
+                               __func__, imxdmac->channel, d->sg, d->sgcount,
+                               d->len, imxdmac->per_address);
+               } else if (d->direction == DMA_MEM_TO_DEV) {
+                       imx_dmav1_writel(imxdma, imxdmac->per_address,
+                                        DMA_DAR(imxdmac->channel));
+                       imx_dmav1_writel(imxdma, imxdmac->ccr_to_device,
+                                        DMA_CCR(imxdmac->channel));
+                       dev_dbg(imxdma->dev, "%s channel: %d sg=%p sgcount=%d "
+                               "total length=%d dev_addr=0x%08x (mem2dev)\n",
+                               __func__, imxdmac->channel, d->sg, d->sgcount,
+                               d->len, imxdmac->per_address);
+               } else {
+                       dev_err(imxdma->dev, "%s channel: %d bad dma mode\n",
+                               __func__, imxdmac->channel);
+                       return -EINVAL;
+               }
+               imxdma_sg_next(d);
  
-       imxdmac->status = DMA_ERROR;
-       imxdma_handle(imxdmac);
+               break;
+       default:
+               return -EINVAL;
+       }
+       imxdma_enable_hw(d);
+       return 0;
  }
  
- static void imxdma_progression(int channel, void *data,
-               struct scatterlist *sg)
+ static void imxdma_tasklet(unsigned long data)
  {
-       struct imxdma_channel *imxdmac = data;
+       struct imxdma_channel *imxdmac = (void *)data;
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       struct imxdma_desc *desc;
  
-       imxdmac->status = DMA_SUCCESS;
-       imxdma_handle(imxdmac);
+       spin_lock(&imxdma->lock);
+       if (list_empty(&imxdmac->ld_active)) {
+               /* Someone might have called terminate all */
+               goto out;
+       }
+       desc = list_first_entry(&imxdmac->ld_active, struct imxdma_desc, node);
+       if (desc->desc.callback)
+               desc->desc.callback(desc->desc.callback_param);
+       dma_cookie_complete(&desc->desc);
+       /* If we are dealing with a cyclic descriptor keep it on ld_active */
+       if (imxdma_chan_is_doing_cyclic(imxdmac))
+               goto out;
+       /* Free 2D slot if it was an interleaved transfer */
+       if (imxdmac->enabled_2d) {
+               imxdma->slots_2d[imxdmac->slot_2d].count--;
+               imxdmac->enabled_2d = false;
+       }
+       list_move_tail(imxdmac->ld_active.next, &imxdmac->ld_free);
+       if (!list_empty(&imxdmac->ld_queue)) {
+               desc = list_first_entry(&imxdmac->ld_queue, struct imxdma_desc,
+                                       node);
+               list_move_tail(imxdmac->ld_queue.next, &imxdmac->ld_active);
+               if (imxdma_xfer_desc(desc) < 0)
+                       dev_warn(imxdma->dev, "%s: channel: %d couldn't xfer desc\n",
+                                __func__, imxdmac->channel);
+       }
+ out:
+       spin_unlock(&imxdma->lock);
  }
  
  static int imxdma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  {
        struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
        struct dma_slave_config *dmaengine_cfg = (void *)arg;
-       int ret;
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       unsigned long flags;
        unsigned int mode = 0;
  
        switch (cmd) {
        case DMA_TERMINATE_ALL:
-               imxdmac->status = DMA_ERROR;
-               imx_dma_disable(imxdmac->imxdma_channel);
+               imxdma_disable_hw(imxdmac);
+               spin_lock_irqsave(&imxdma->lock, flags);
+               list_splice_tail_init(&imxdmac->ld_active, &imxdmac->ld_free);
+               list_splice_tail_init(&imxdmac->ld_queue, &imxdmac->ld_free);
+               spin_unlock_irqrestore(&imxdma->lock, flags);
                return 0;
        case DMA_SLAVE_CONFIG:
                if (dmaengine_cfg->direction == DMA_DEV_TO_MEM) {
                        mode = IMX_DMA_MEMSIZE_32;
                        break;
                }
-               ret = imx_dma_config_channel(imxdmac->imxdma_channel,
-                               mode | IMX_DMA_TYPE_FIFO,
-                               IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR,
-                               imxdmac->dma_request, 1);
-               if (ret)
-                       return ret;
  
-               imx_dma_config_burstlen(imxdmac->imxdma_channel,
-                               imxdmac->watermark_level * imxdmac->word_size);
+               imxdmac->hw_chaining = 1;
+               if (!imxdma_hw_chain(imxdmac))
+                       return -EINVAL;
+               imxdmac->ccr_from_device = (mode | IMX_DMA_TYPE_FIFO) |
+                       ((IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR) << 2) |
+                       CCR_REN;
+               imxdmac->ccr_to_device =
+                       (IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR) |
+                       ((mode | IMX_DMA_TYPE_FIFO) << 2) | CCR_REN;
+               imx_dmav1_writel(imxdma, imxdmac->dma_request,
+                                DMA_RSSR(imxdmac->channel));
+               /* Set burst length */
+               imx_dmav1_writel(imxdma, imxdmac->watermark_level *
+                               imxdmac->word_size, DMA_BLR(imxdmac->channel));
  
                return 0;
        default:
@@@ -151,43 -668,20 +667,20 @@@ static enum dma_status imxdma_tx_status
                                            dma_cookie_t cookie,
                                            struct dma_tx_state *txstate)
  {
-       struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
-       dma_cookie_t last_used;
-       enum dma_status ret;
-       last_used = chan->cookie;
-       ret = dma_async_is_complete(cookie, imxdmac->last_completed, last_used);
-       dma_set_tx_state(txstate, imxdmac->last_completed, last_used, 0);
-       return ret;
- }
- static dma_cookie_t imxdma_assign_cookie(struct imxdma_channel *imxdma)
- {
-       dma_cookie_t cookie = imxdma->chan.cookie;
-       if (++cookie < 0)
-               cookie = 1;
-       imxdma->chan.cookie = cookie;
-       imxdma->desc.cookie = cookie;
-       return cookie;
+       return dma_cookie_status(chan, cookie, txstate);
  }
  
  static dma_cookie_t imxdma_tx_submit(struct dma_async_tx_descriptor *tx)
  {
        struct imxdma_channel *imxdmac = to_imxdma_chan(tx->chan);
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
        dma_cookie_t cookie;
+       unsigned long flags;
  
-       spin_lock_irq(&imxdmac->lock);
-       cookie = imxdma_assign_cookie(imxdmac);
-       imx_dma_enable(imxdmac->imxdma_channel);
-       spin_unlock_irq(&imxdmac->lock);
+       spin_lock_irqsave(&imxdma->lock, flags);
+       list_move_tail(imxdmac->ld_free.next, &imxdmac->ld_queue);
+       cookie = dma_cookie_assign(tx);
+       spin_unlock_irqrestore(&imxdma->lock, flags);
  
        return cookie;
  }
@@@ -197,23 -691,52 +690,52 @@@ static int imxdma_alloc_chan_resources(
        struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
        struct imx_dma_data *data = chan->private;
  
-       imxdmac->dma_request = data->dma_request;
+       if (data != NULL)
+               imxdmac->dma_request = data->dma_request;
  
-       dma_async_tx_descriptor_init(&imxdmac->desc, chan);
-       imxdmac->desc.tx_submit = imxdma_tx_submit;
-       /* txd.flags will be overwritten in prep funcs */
-       imxdmac->desc.flags = DMA_CTRL_ACK;
+       while (imxdmac->descs_allocated < IMXDMA_MAX_CHAN_DESCRIPTORS) {
+               struct imxdma_desc *desc;
  
-       imxdmac->status = DMA_SUCCESS;
+               desc = kzalloc(sizeof(*desc), GFP_KERNEL);
+               if (!desc)
+                       break;
+               __memzero(&desc->desc, sizeof(struct dma_async_tx_descriptor));
+               dma_async_tx_descriptor_init(&desc->desc, chan);
+               desc->desc.tx_submit = imxdma_tx_submit;
+               /* txd.flags will be overwritten in prep funcs */
+               desc->desc.flags = DMA_CTRL_ACK;
+               desc->status = DMA_SUCCESS;
+               list_add_tail(&desc->node, &imxdmac->ld_free);
+               imxdmac->descs_allocated++;
+       }
  
-       return 0;
+       if (!imxdmac->descs_allocated)
+               return -ENOMEM;
+       return imxdmac->descs_allocated;
  }
  
  static void imxdma_free_chan_resources(struct dma_chan *chan)
  {
        struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       struct imxdma_desc *desc, *_desc;
+       unsigned long flags;
+       spin_lock_irqsave(&imxdma->lock, flags);
+       imxdma_disable_hw(imxdmac);
+       list_splice_tail_init(&imxdmac->ld_active, &imxdmac->ld_free);
+       list_splice_tail_init(&imxdmac->ld_queue, &imxdmac->ld_free);
  
-       imx_dma_disable(imxdmac->imxdma_channel);
+       spin_unlock_irqrestore(&imxdma->lock, flags);
+       list_for_each_entry_safe(desc, _desc, &imxdmac->ld_free, node) {
+               kfree(desc);
+               imxdmac->descs_allocated--;
+       }
+       INIT_LIST_HEAD(&imxdmac->ld_free);
  
        if (imxdmac->sg_list) {
                kfree(imxdmac->sg_list);
  static struct dma_async_tx_descriptor *imxdma_prep_slave_sg(
                struct dma_chan *chan, struct scatterlist *sgl,
                unsigned int sg_len, enum dma_transfer_direction direction,
-               unsigned long flags)
+               unsigned long flags, void *context)
  {
        struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
        struct scatterlist *sg;
-       int i, ret, dma_length = 0;
-       unsigned int dmamode;
+       int i, dma_length = 0;
+       struct imxdma_desc *desc;
  
-       if (imxdmac->status == DMA_IN_PROGRESS)
+       if (list_empty(&imxdmac->ld_free) ||
+           imxdma_chan_is_doing_cyclic(imxdmac))
                return NULL;
  
-       imxdmac->status = DMA_IN_PROGRESS;
+       desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  
        for_each_sg(sgl, sg, sg_len, i) {
                dma_length += sg->length;
        }
  
-       if (direction == DMA_DEV_TO_MEM)
-               dmamode = DMA_MODE_READ;
-       else
-               dmamode = DMA_MODE_WRITE;
        switch (imxdmac->word_size) {
        case DMA_SLAVE_BUSWIDTH_4_BYTES:
                if (sgl->length & 3 || sgl->dma_address & 3)
                return NULL;
        }
  
-       ret = imx_dma_setup_sg(imxdmac->imxdma_channel, sgl, sg_len,
-                dma_length, imxdmac->per_address, dmamode);
-       if (ret)
-               return NULL;
+       desc->type = IMXDMA_DESC_SLAVE_SG;
+       desc->sg = sgl;
+       desc->sgcount = sg_len;
+       desc->len = dma_length;
+       desc->direction = direction;
+       if (direction == DMA_DEV_TO_MEM) {
+               desc->src = imxdmac->per_address;
+       } else {
+               desc->dest = imxdmac->per_address;
+       }
+       desc->desc.callback = NULL;
+       desc->desc.callback_param = NULL;
  
-       return &imxdmac->desc;
+       return &desc->desc;
  }
  
  static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic(
                struct dma_chan *chan, dma_addr_t dma_addr, size_t buf_len,
-               size_t period_len, enum dma_transfer_direction direction)
+               size_t period_len, enum dma_transfer_direction direction,
+               void *context)
  {
        struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
        struct imxdma_engine *imxdma = imxdmac->imxdma;
-       int i, ret;
+       struct imxdma_desc *desc;
+       int i;
        unsigned int periods = buf_len / period_len;
-       unsigned int dmamode;
  
        dev_dbg(imxdma->dev, "%s channel: %d buf_len=%d period_len=%d\n",
                        __func__, imxdmac->channel, buf_len, period_len);
  
-       if (imxdmac->status == DMA_IN_PROGRESS)
+       if (list_empty(&imxdmac->ld_free) ||
+           imxdma_chan_is_doing_cyclic(imxdmac))
                return NULL;
-       imxdmac->status = DMA_IN_PROGRESS;
  
-       ret = imx_dma_setup_progression_handler(imxdmac->imxdma_channel,
-                       imxdma_progression);
-       if (ret) {
-               dev_err(imxdma->dev, "Failed to setup the DMA handler\n");
-               return NULL;
-       }
+       desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  
        if (imxdmac->sg_list)
                kfree(imxdmac->sg_list);
        imxdmac->sg_list[periods].page_link =
                ((unsigned long)imxdmac->sg_list | 0x01) & ~0x02;
  
-       if (direction == DMA_DEV_TO_MEM)
-               dmamode = DMA_MODE_READ;
-       else
-               dmamode = DMA_MODE_WRITE;
+       desc->type = IMXDMA_DESC_CYCLIC;
+       desc->sg = imxdmac->sg_list;
+       desc->sgcount = periods;
+       desc->len = IMX_DMA_LENGTH_LOOP;
+       desc->direction = direction;
+       if (direction == DMA_DEV_TO_MEM) {
+               desc->src = imxdmac->per_address;
+       } else {
+               desc->dest = imxdmac->per_address;
+       }
+       desc->desc.callback = NULL;
+       desc->desc.callback_param = NULL;
+       return &desc->desc;
+ }
+ static struct dma_async_tx_descriptor *imxdma_prep_dma_memcpy(
+       struct dma_chan *chan, dma_addr_t dest,
+       dma_addr_t src, size_t len, unsigned long flags)
+ {
+       struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       struct imxdma_desc *desc;
  
-       ret = imx_dma_setup_sg(imxdmac->imxdma_channel, imxdmac->sg_list, periods,
-                IMX_DMA_LENGTH_LOOP, imxdmac->per_address, dmamode);
-       if (ret)
+       dev_dbg(imxdma->dev, "%s channel: %d src=0x%x dst=0x%x len=%d\n",
+                       __func__, imxdmac->channel, src, dest, len);
+       if (list_empty(&imxdmac->ld_free) ||
+           imxdma_chan_is_doing_cyclic(imxdmac))
                return NULL;
  
-       return &imxdmac->desc;
+       desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
+       desc->type = IMXDMA_DESC_MEMCPY;
+       desc->src = src;
+       desc->dest = dest;
+       desc->len = len;
+       desc->direction = DMA_MEM_TO_MEM;
+       desc->config_port = IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR;
+       desc->config_mem = IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR;
+       desc->desc.callback = NULL;
+       desc->desc.callback_param = NULL;
+       return &desc->desc;
+ }
+ static struct dma_async_tx_descriptor *imxdma_prep_dma_interleaved(
+       struct dma_chan *chan, struct dma_interleaved_template *xt,
+       unsigned long flags)
+ {
+       struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       struct imxdma_desc *desc;
+       dev_dbg(imxdma->dev, "%s channel: %d src_start=0x%x dst_start=0x%x\n"
+               "   src_sgl=%s dst_sgl=%s numf=%d frame_size=%d\n", __func__,
+               imxdmac->channel, xt->src_start, xt->dst_start,
+               xt->src_sgl ? "true" : "false", xt->dst_sgl ? "true" : "false",
+               xt->numf, xt->frame_size);
+       if (list_empty(&imxdmac->ld_free) ||
+           imxdma_chan_is_doing_cyclic(imxdmac))
+               return NULL;
+       if (xt->frame_size != 1 || xt->numf <= 0 || xt->dir != DMA_MEM_TO_MEM)
+               return NULL;
+       desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
+       desc->type = IMXDMA_DESC_INTERLEAVED;
+       desc->src = xt->src_start;
+       desc->dest = xt->dst_start;
+       desc->x = xt->sgl[0].size;
+       desc->y = xt->numf;
+       desc->w = xt->sgl[0].icg + desc->x;
+       desc->len = desc->x * desc->y;
+       desc->direction = DMA_MEM_TO_MEM;
+       desc->config_port = IMX_DMA_MEMSIZE_32;
+       desc->config_mem = IMX_DMA_MEMSIZE_32;
+       if (xt->src_sgl)
+               desc->config_mem |= IMX_DMA_TYPE_2D;
+       if (xt->dst_sgl)
+               desc->config_port |= IMX_DMA_TYPE_2D;
+       desc->desc.callback = NULL;
+       desc->desc.callback_param = NULL;
+       return &desc->desc;
  }
  
  static void imxdma_issue_pending(struct dma_chan *chan)
  {
-       /*
-        * Nothing to do. We only have a single descriptor
-        */
+       struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
+       struct imxdma_engine *imxdma = imxdmac->imxdma;
+       struct imxdma_desc *desc;
+       unsigned long flags;
+       spin_lock_irqsave(&imxdma->lock, flags);
+       if (list_empty(&imxdmac->ld_active) &&
+           !list_empty(&imxdmac->ld_queue)) {
+               desc = list_first_entry(&imxdmac->ld_queue,
+                                       struct imxdma_desc, node);
+               if (imxdma_xfer_desc(desc) < 0) {
+                       dev_warn(imxdma->dev,
+                                "%s: channel: %d couldn't issue DMA xfer\n",
+                                __func__, imxdmac->channel);
+               } else {
+                       list_move_tail(imxdmac->ld_queue.next,
+                                      &imxdmac->ld_active);
+               }
+       }
+       spin_unlock_irqrestore(&imxdma->lock, flags);
  }
  
  static int __init imxdma_probe(struct platform_device *pdev)
- {
      {
        struct imxdma_engine *imxdma;
        int ret, i;
  
        imxdma = kzalloc(sizeof(*imxdma), GFP_KERNEL);
        if (!imxdma)
                return -ENOMEM;
  
+       if (cpu_is_mx1()) {
+               imxdma->base = MX1_IO_ADDRESS(MX1_DMA_BASE_ADDR);
+       } else if (cpu_is_mx21()) {
+               imxdma->base = MX21_IO_ADDRESS(MX21_DMA_BASE_ADDR);
+       } else if (cpu_is_mx27()) {
+               imxdma->base = MX27_IO_ADDRESS(MX27_DMA_BASE_ADDR);
+       } else {
+               kfree(imxdma);
+               return 0;
+       }
+       imxdma->dma_clk = clk_get(NULL, "dma");
+       if (IS_ERR(imxdma->dma_clk))
+               return PTR_ERR(imxdma->dma_clk);
+       clk_enable(imxdma->dma_clk);
+       /* reset DMA module */
+       imx_dmav1_writel(imxdma, DCR_DRST, DMA_DCR);
+       if (cpu_is_mx1()) {
+               ret = request_irq(MX1_DMA_INT, dma_irq_handler, 0, "DMA", imxdma);
+               if (ret) {
+                       dev_warn(imxdma->dev, "Can't register IRQ for DMA\n");
+                       kfree(imxdma);
+                       return ret;
+               }
+               ret = request_irq(MX1_DMA_ERR, imxdma_err_handler, 0, "DMA", imxdma);
+               if (ret) {
+                       dev_warn(imxdma->dev, "Can't register ERRIRQ for DMA\n");
+                       free_irq(MX1_DMA_INT, NULL);
+                       kfree(imxdma);
+                       return ret;
+               }
+       }
+       /* enable DMA module */
+       imx_dmav1_writel(imxdma, DCR_DEN, DMA_DCR);
+       /* clear all interrupts */
+       imx_dmav1_writel(imxdma, (1 << IMX_DMA_CHANNELS) - 1, DMA_DISR);
+       /* disable interrupts */
+       imx_dmav1_writel(imxdma, (1 << IMX_DMA_CHANNELS) - 1, DMA_DIMR);
        INIT_LIST_HEAD(&imxdma->dma_device.channels);
  
        dma_cap_set(DMA_SLAVE, imxdma->dma_device.cap_mask);
        dma_cap_set(DMA_CYCLIC, imxdma->dma_device.cap_mask);
+       dma_cap_set(DMA_MEMCPY, imxdma->dma_device.cap_mask);
+       dma_cap_set(DMA_INTERLEAVE, imxdma->dma_device.cap_mask);
+       /* Initialize 2D global parameters */
+       for (i = 0; i < IMX_DMA_2D_SLOTS; i++)
+               imxdma->slots_2d[i].count = 0;
+       spin_lock_init(&imxdma->lock);
  
        /* Initialize channel parameters */
-       for (i = 0; i < MAX_DMA_CHANNELS; i++) {
+       for (i = 0; i < IMX_DMA_CHANNELS; i++) {
                struct imxdma_channel *imxdmac = &imxdma->channel[i];
  
-               imxdmac->imxdma_channel = imx_dma_request_by_prio("dmaengine",
-                               DMA_PRIO_MEDIUM);
-               if ((int)imxdmac->channel < 0) {
-                       ret = -ENODEV;
-                       goto err_init;
+               if (cpu_is_mx21() || cpu_is_mx27()) {
+                       ret = request_irq(MX2x_INT_DMACH0 + i,
+                                       dma_irq_handler, 0, "DMA", imxdma);
+                       if (ret) {
+                               dev_warn(imxdma->dev, "Can't register IRQ %d "
+                                        "for DMA channel %d\n",
+                                        MX2x_INT_DMACH0 + i, i);
+                               goto err_init;
+                       }
+                       init_timer(&imxdmac->watchdog);
+                       imxdmac->watchdog.function = &imxdma_watchdog;
+                       imxdmac->watchdog.data = (unsigned long)imxdmac;
                }
  
-               imx_dma_setup_handlers(imxdmac->imxdma_channel,
-                      imxdma_irq_handler, imxdma_err_handler, imxdmac);
                imxdmac->imxdma = imxdma;
-               spin_lock_init(&imxdmac->lock);
  
+               INIT_LIST_HEAD(&imxdmac->ld_queue);
+               INIT_LIST_HEAD(&imxdmac->ld_free);
+               INIT_LIST_HEAD(&imxdmac->ld_active);
+               tasklet_init(&imxdmac->dma_tasklet, imxdma_tasklet,
+                            (unsigned long)imxdmac);
                imxdmac->chan.device = &imxdma->dma_device;
+               dma_cookie_init(&imxdmac->chan);
                imxdmac->channel = i;
  
                /* Add the channel to the DMAC list */
-               list_add_tail(&imxdmac->chan.device_node, &imxdma->dma_device.channels);
+               list_add_tail(&imxdmac->chan.device_node,
+                             &imxdma->dma_device.channels);
        }
  
        imxdma->dev = &pdev->dev;
        imxdma->dma_device.device_tx_status = imxdma_tx_status;
        imxdma->dma_device.device_prep_slave_sg = imxdma_prep_slave_sg;
        imxdma->dma_device.device_prep_dma_cyclic = imxdma_prep_dma_cyclic;
+       imxdma->dma_device.device_prep_dma_memcpy = imxdma_prep_dma_memcpy;
+       imxdma->dma_device.device_prep_interleaved_dma = imxdma_prep_dma_interleaved;
        imxdma->dma_device.device_control = imxdma_control;
        imxdma->dma_device.device_issue_pending = imxdma_issue_pending;
  
        platform_set_drvdata(pdev, imxdma);
  
+       imxdma->dma_device.copy_align = 2; /* 2^2 = 4 bytes alignment */
        imxdma->dma_device.dev->dma_parms = &imxdma->dma_parms;
        dma_set_max_seg_size(imxdma->dma_device.dev, 0xffffff);
  
        return 0;
  
  err_init:
-       while (--i >= 0) {
-               struct imxdma_channel *imxdmac = &imxdma->channel[i];
-               imx_dma_free(imxdmac->imxdma_channel);
+       if (cpu_is_mx21() || cpu_is_mx27()) {
+               while (--i >= 0)
+                       free_irq(MX2x_INT_DMACH0 + i, NULL);
+       } else if cpu_is_mx1() {
+               free_irq(MX1_DMA_INT, NULL);
+               free_irq(MX1_DMA_ERR, NULL);
        }
  
        kfree(imxdma);
@@@ -415,10 -1104,12 +1103,12 @@@ static int __exit imxdma_remove(struct 
  
          dma_async_device_unregister(&imxdma->dma_device);
  
-       for (i = 0; i < MAX_DMA_CHANNELS; i++) {
-               struct imxdma_channel *imxdmac = &imxdma->channel[i];
-                imx_dma_free(imxdmac->imxdma_channel);
+       if (cpu_is_mx21() || cpu_is_mx27()) {
+               for (i = 0; i < IMX_DMA_CHANNELS; i++)
+                       free_irq(MX2x_INT_DMACH0 + i, NULL);
+       } else if cpu_is_mx1() {
+               free_irq(MX1_DMA_INT, NULL);
+               free_irq(MX1_DMA_ERR, NULL);
        }
  
          kfree(imxdma);
diff --combined drivers/dma/imx-sdma.c
index 63540d3e21534ae8cfe596c1d03a4ce850bcc200,434fb610aa1af09f228383b5e14c81f7c1224e81..d3e38e28bb6b19a480eb1b05b732a0dc2f40eb7f
@@@ -20,6 -20,7 +20,7 @@@
  #include <linux/init.h>
  #include <linux/module.h>
  #include <linux/types.h>
+ #include <linux/bitops.h>
  #include <linux/mm.h>
  #include <linux/interrupt.h>
  #include <linux/clk.h>
  #include <linux/dmaengine.h>
  #include <linux/of.h>
  #include <linux/of_device.h>
 -#include <linux/module.h>
  
  #include <asm/irq.h>
  #include <mach/sdma.h>
  #include <mach/dma.h>
  #include <mach/hardware.h>
  
+ #include "dmaengine.h"
  /* SDMA registers */
  #define SDMA_H_C0PTR          0x000
  #define SDMA_H_INTR           0x004
@@@ -259,19 -263,18 +262,18 @@@ struct sdma_channel 
        unsigned int                    pc_from_device, pc_to_device;
        unsigned long                   flags;
        dma_addr_t                      per_address;
-       u32                             event_mask0, event_mask1;
-       u32                             watermark_level;
+       unsigned long                   event_mask[2];
+       unsigned long                   watermark_level;
        u32                             shp_addr, per_addr;
        struct dma_chan                 chan;
        spinlock_t                      lock;
        struct dma_async_tx_descriptor  desc;
-       dma_cookie_t                    last_completed;
        enum dma_status                 status;
        unsigned int                    chn_count;
        unsigned int                    chn_real_count;
  };
  
- #define IMX_DMA_SG_LOOP               (1 << 0)
+ #define IMX_DMA_SG_LOOP               BIT(0)
  
  #define MAX_DMA_CHANNELS 32
  #define MXC_SDMA_DEFAULT_PRIORITY 1
@@@ -345,9 -348,9 +347,9 @@@ static const struct of_device_id sdma_d
  };
  MODULE_DEVICE_TABLE(of, sdma_dt_ids);
  
- #define SDMA_H_CONFIG_DSPDMA  (1 << 12) /* indicates if the DSPDMA is used */
- #define SDMA_H_CONFIG_RTD_PINS        (1 << 11) /* indicates if Real-Time Debug pins are enabled */
- #define SDMA_H_CONFIG_ACR     (1 << 4)  /* indicates if AHB freq /core freq = 2 or 1 */
+ #define SDMA_H_CONFIG_DSPDMA  BIT(12) /* indicates if the DSPDMA is used */
+ #define SDMA_H_CONFIG_RTD_PINS        BIT(11) /* indicates if Real-Time Debug pins are enabled */
+ #define SDMA_H_CONFIG_ACR     BIT(4)  /* indicates if AHB freq /core freq = 2 or 1 */
  #define SDMA_H_CONFIG_CSM     (3)       /* indicates which context switch mode is selected*/
  
  static inline u32 chnenbl_ofs(struct sdma_engine *sdma, unsigned int event)
@@@ -362,37 -365,42 +364,42 @@@ static int sdma_config_ownership(struc
  {
        struct sdma_engine *sdma = sdmac->sdma;
        int channel = sdmac->channel;
-       u32 evt, mcu, dsp;
+       unsigned long evt, mcu, dsp;
  
        if (event_override && mcu_override && dsp_override)
                return -EINVAL;
  
-       evt = __raw_readl(sdma->regs + SDMA_H_EVTOVR);
-       mcu = __raw_readl(sdma->regs + SDMA_H_HOSTOVR);
-       dsp = __raw_readl(sdma->regs + SDMA_H_DSPOVR);
+       evt = readl_relaxed(sdma->regs + SDMA_H_EVTOVR);
+       mcu = readl_relaxed(sdma->regs + SDMA_H_HOSTOVR);
+       dsp = readl_relaxed(sdma->regs + SDMA_H_DSPOVR);
  
        if (dsp_override)
-               dsp &= ~(1 << channel);
+               __clear_bit(channel, &dsp);
        else
-               dsp |= (1 << channel);
+               __set_bit(channel, &dsp);
  
        if (event_override)
-               evt &= ~(1 << channel);
+               __clear_bit(channel, &evt);
        else
-               evt |= (1 << channel);
+               __set_bit(channel, &evt);
  
        if (mcu_override)
-               mcu &= ~(1 << channel);
+               __clear_bit(channel, &mcu);
        else
-               mcu |= (1 << channel);
+               __set_bit(channel, &mcu);
  
-       __raw_writel(evt, sdma->regs + SDMA_H_EVTOVR);
-       __raw_writel(mcu, sdma->regs + SDMA_H_HOSTOVR);
-       __raw_writel(dsp, sdma->regs + SDMA_H_DSPOVR);
+       writel_relaxed(evt, sdma->regs + SDMA_H_EVTOVR);
+       writel_relaxed(mcu, sdma->regs + SDMA_H_HOSTOVR);
+       writel_relaxed(dsp, sdma->regs + SDMA_H_DSPOVR);
  
        return 0;
  }
  
+ static void sdma_enable_channel(struct sdma_engine *sdma, int channel)
+ {
+       writel(BIT(channel), sdma->regs + SDMA_H_START);
+ }
  /*
   * sdma_run_channel - run a channel and wait till it's done
   */
@@@ -404,7 -412,7 +411,7 @@@ static int sdma_run_channel(struct sdma
  
        init_completion(&sdmac->done);
  
-       __raw_writel(1 << channel, sdma->regs + SDMA_H_START);
+       sdma_enable_channel(sdma, channel);
  
        ret = wait_for_completion_timeout(&sdmac->done, HZ);
  
@@@ -451,12 -459,12 +458,12 @@@ static void sdma_event_enable(struct sd
  {
        struct sdma_engine *sdma = sdmac->sdma;
        int channel = sdmac->channel;
-       u32 val;
+       unsigned long val;
        u32 chnenbl = chnenbl_ofs(sdma, event);
  
-       val = __raw_readl(sdma->regs + chnenbl);
-       val |= (1 << channel);
-       __raw_writel(val, sdma->regs + chnenbl);
+       val = readl_relaxed(sdma->regs + chnenbl);
+       __set_bit(channel, &val);
+       writel_relaxed(val, sdma->regs + chnenbl);
  }
  
  static void sdma_event_disable(struct sdma_channel *sdmac, unsigned int event)
        struct sdma_engine *sdma = sdmac->sdma;
        int channel = sdmac->channel;
        u32 chnenbl = chnenbl_ofs(sdma, event);
-       u32 val;
+       unsigned long val;
  
-       val = __raw_readl(sdma->regs + chnenbl);
-       val &= ~(1 << channel);
-       __raw_writel(val, sdma->regs + chnenbl);
+       val = readl_relaxed(sdma->regs + chnenbl);
+       __clear_bit(channel, &val);
+       writel_relaxed(val, sdma->regs + chnenbl);
  }
  
  static void sdma_handle_channel_loop(struct sdma_channel *sdmac)
@@@ -522,7 -530,7 +529,7 @@@ static void mxc_sdma_handle_channel_nor
        else
                sdmac->status = DMA_SUCCESS;
  
-       sdmac->last_completed = sdmac->desc.cookie;
+       dma_cookie_complete(&sdmac->desc);
        if (sdmac->desc.callback)
                sdmac->desc.callback(sdmac->desc.callback_param);
  }
@@@ -544,10 -552,10 +551,10 @@@ static void mxc_sdma_handle_channel(str
  static irqreturn_t sdma_int_handler(int irq, void *dev_id)
  {
        struct sdma_engine *sdma = dev_id;
-       u32 stat;
+       unsigned long stat;
  
-       stat = __raw_readl(sdma->regs + SDMA_H_INTR);
-       __raw_writel(stat, sdma->regs + SDMA_H_INTR);
+       stat = readl_relaxed(sdma->regs + SDMA_H_INTR);
+       writel_relaxed(stat, sdma->regs + SDMA_H_INTR);
  
        while (stat) {
                int channel = fls(stat) - 1;
  
                mxc_sdma_handle_channel(sdmac);
  
-               stat &= ~(1 << channel);
+               __clear_bit(channel, &stat);
        }
  
        return IRQ_HANDLED;
@@@ -663,11 -671,11 +670,11 @@@ static int sdma_load_context(struct sdm
                return load_address;
  
        dev_dbg(sdma->dev, "load_address = %d\n", load_address);
-       dev_dbg(sdma->dev, "wml = 0x%08x\n", sdmac->watermark_level);
+       dev_dbg(sdma->dev, "wml = 0x%08x\n", (u32)sdmac->watermark_level);
        dev_dbg(sdma->dev, "shp_addr = 0x%08x\n", sdmac->shp_addr);
        dev_dbg(sdma->dev, "per_addr = 0x%08x\n", sdmac->per_addr);
-       dev_dbg(sdma->dev, "event_mask0 = 0x%08x\n", sdmac->event_mask0);
-       dev_dbg(sdma->dev, "event_mask1 = 0x%08x\n", sdmac->event_mask1);
+       dev_dbg(sdma->dev, "event_mask0 = 0x%08x\n", (u32)sdmac->event_mask[0]);
+       dev_dbg(sdma->dev, "event_mask1 = 0x%08x\n", (u32)sdmac->event_mask[1]);
  
        mutex_lock(&sdma->channel_0_lock);
  
        /* Send by context the event mask,base address for peripheral
         * and watermark level
         */
-       context->gReg[0] = sdmac->event_mask1;
-       context->gReg[1] = sdmac->event_mask0;
+       context->gReg[0] = sdmac->event_mask[1];
+       context->gReg[1] = sdmac->event_mask[0];
        context->gReg[2] = sdmac->per_addr;
        context->gReg[6] = sdmac->shp_addr;
        context->gReg[7] = sdmac->watermark_level;
@@@ -701,7 -709,7 +708,7 @@@ static void sdma_disable_channel(struc
        struct sdma_engine *sdma = sdmac->sdma;
        int channel = sdmac->channel;
  
-       __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP);
+       writel_relaxed(BIT(channel), sdma->regs + SDMA_H_STATSTOP);
        sdmac->status = DMA_ERROR;
  }
  
@@@ -711,13 -719,13 +718,13 @@@ static int sdma_config_channel(struct s
  
        sdma_disable_channel(sdmac);
  
-       sdmac->event_mask0 = 0;
-       sdmac->event_mask1 = 0;
+       sdmac->event_mask[0] = 0;
+       sdmac->event_mask[1] = 0;
        sdmac->shp_addr = 0;
        sdmac->per_addr = 0;
  
        if (sdmac->event_id0) {
-               if (sdmac->event_id0 > 32)
+               if (sdmac->event_id0 >= sdmac->sdma->num_events)
                        return -EINVAL;
                sdma_event_enable(sdmac, sdmac->event_id0);
        }
                        (sdmac->peripheral_type != IMX_DMATYPE_DSP)) {
                /* Handle multiple event channels differently */
                if (sdmac->event_id1) {
-                       sdmac->event_mask1 = 1 << (sdmac->event_id1 % 32);
+                       sdmac->event_mask[1] = BIT(sdmac->event_id1 % 32);
                        if (sdmac->event_id1 > 31)
-                               sdmac->watermark_level |= 1 << 31;
-                       sdmac->event_mask0 = 1 << (sdmac->event_id0 % 32);
+                               __set_bit(31, &sdmac->watermark_level);
+                       sdmac->event_mask[0] = BIT(sdmac->event_id0 % 32);
                        if (sdmac->event_id0 > 31)
-                               sdmac->watermark_level |= 1 << 30;
+                               __set_bit(30, &sdmac->watermark_level);
                } else {
-                       sdmac->event_mask0 = 1 << sdmac->event_id0;
-                       sdmac->event_mask1 = 1 << (sdmac->event_id0 - 32);
+                       __set_bit(sdmac->event_id0, sdmac->event_mask);
                }
                /* Watermark Level */
                sdmac->watermark_level |= sdmac->watermark_level;
@@@ -774,7 -781,7 +780,7 @@@ static int sdma_set_channel_priority(st
                return -EINVAL;
        }
  
-       __raw_writel(priority, sdma->regs + SDMA_CHNPRI_0 + 4 * channel);
+       writel_relaxed(priority, sdma->regs + SDMA_CHNPRI_0 + 4 * channel);
  
        return 0;
  }
@@@ -796,8 -803,6 +802,6 @@@ static int sdma_request_channel(struct 
        sdma->channel_control[channel].base_bd_ptr = sdmac->bd_phys;
        sdma->channel_control[channel].current_bd_ptr = sdmac->bd_phys;
  
-       clk_enable(sdma->clk);
        sdma_set_channel_priority(sdmac, MXC_SDMA_DEFAULT_PRIORITY);
  
        init_completion(&sdmac->done);
@@@ -810,24 -815,6 +814,6 @@@ out
        return ret;
  }
  
- static void sdma_enable_channel(struct sdma_engine *sdma, int channel)
- {
-       __raw_writel(1 << channel, sdma->regs + SDMA_H_START);
- }
- static dma_cookie_t sdma_assign_cookie(struct sdma_channel *sdmac)
- {
-       dma_cookie_t cookie = sdmac->chan.cookie;
-       if (++cookie < 0)
-               cookie = 1;
-       sdmac->chan.cookie = cookie;
-       sdmac->desc.cookie = cookie;
-       return cookie;
- }
  static struct sdma_channel *to_sdma_chan(struct dma_chan *chan)
  {
        return container_of(chan, struct sdma_channel, chan);
@@@ -837,14 -824,11 +823,11 @@@ static dma_cookie_t sdma_tx_submit(stru
  {
        unsigned long flags;
        struct sdma_channel *sdmac = to_sdma_chan(tx->chan);
-       struct sdma_engine *sdma = sdmac->sdma;
        dma_cookie_t cookie;
  
        spin_lock_irqsave(&sdmac->lock, flags);
  
-       cookie = sdma_assign_cookie(sdmac);
-       sdma_enable_channel(sdma, sdmac->channel);
+       cookie = dma_cookie_assign(tx);
  
        spin_unlock_irqrestore(&sdmac->lock, flags);
  
@@@ -875,11 -859,14 +858,14 @@@ static int sdma_alloc_chan_resources(st
  
        sdmac->peripheral_type = data->peripheral_type;
        sdmac->event_id0 = data->dma_request;
-       ret = sdma_set_channel_priority(sdmac, prio);
+       clk_enable(sdmac->sdma->clk);
+       ret = sdma_request_channel(sdmac);
        if (ret)
                return ret;
  
-       ret = sdma_request_channel(sdmac);
+       ret = sdma_set_channel_priority(sdmac, prio);
        if (ret)
                return ret;
  
@@@ -916,7 -903,7 +902,7 @@@ static void sdma_free_chan_resources(st
  static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
                struct dma_chan *chan, struct scatterlist *sgl,
                unsigned int sg_len, enum dma_transfer_direction direction,
-               unsigned long flags)
+               unsigned long flags, void *context)
  {
        struct sdma_channel *sdmac = to_sdma_chan(chan);
        struct sdma_engine *sdma = sdmac->sdma;
@@@ -1014,7 -1001,8 +1000,8 @@@ err_out
  
  static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic(
                struct dma_chan *chan, dma_addr_t dma_addr, size_t buf_len,
-               size_t period_len, enum dma_transfer_direction direction)
+               size_t period_len, enum dma_transfer_direction direction,
+               void *context)
  {
        struct sdma_channel *sdmac = to_sdma_chan(chan);
        struct sdma_engine *sdma = sdmac->sdma;
@@@ -1128,7 -1116,7 +1115,7 @@@ static enum dma_status sdma_tx_status(s
  
        last_used = chan->cookie;
  
-       dma_set_tx_state(txstate, sdmac->last_completed, last_used,
+       dma_set_tx_state(txstate, chan->completed_cookie, last_used,
                        sdmac->chn_count - sdmac->chn_real_count);
  
        return sdmac->status;
  
  static void sdma_issue_pending(struct dma_chan *chan)
  {
-       /*
-        * Nothing to do. We only have a single descriptor
-        */
+       struct sdma_channel *sdmac = to_sdma_chan(chan);
+       struct sdma_engine *sdma = sdmac->sdma;
+       if (sdmac->status == DMA_IN_PROGRESS)
+               sdma_enable_channel(sdma, sdmac->channel);
  }
  
  #define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1       34
@@@ -1230,7 -1220,7 +1219,7 @@@ static int __init sdma_init(struct sdma
        clk_enable(sdma->clk);
  
        /* Be sure SDMA has not started yet */
-       __raw_writel(0, sdma->regs + SDMA_H_C0PTR);
+       writel_relaxed(0, sdma->regs + SDMA_H_C0PTR);
  
        sdma->channel_control = dma_alloc_coherent(NULL,
                        MAX_DMA_CHANNELS * sizeof (struct sdma_channel_control) +
  
        /* disable all channels */
        for (i = 0; i < sdma->num_events; i++)
-               __raw_writel(0, sdma->regs + chnenbl_ofs(sdma, i));
+               writel_relaxed(0, sdma->regs + chnenbl_ofs(sdma, i));
  
        /* All channels have priority 0 */
        for (i = 0; i < MAX_DMA_CHANNELS; i++)
-               __raw_writel(0, sdma->regs + SDMA_CHNPRI_0 + i * 4);
+               writel_relaxed(0, sdma->regs + SDMA_CHNPRI_0 + i * 4);
  
        ret = sdma_request_channel(&sdma->channel[0]);
        if (ret)
        sdma_config_ownership(&sdma->channel[0], false, true, false);
  
        /* Set Command Channel (Channel Zero) */
-       __raw_writel(0x4050, sdma->regs + SDMA_CHN0ADDR);
+       writel_relaxed(0x4050, sdma->regs + SDMA_CHN0ADDR);
  
        /* Set bits of CONFIG register but with static context switching */
        /* FIXME: Check whether to set ACR bit depending on clock ratios */
-       __raw_writel(0, sdma->regs + SDMA_H_CONFIG);
+       writel_relaxed(0, sdma->regs + SDMA_H_CONFIG);
  
-       __raw_writel(ccb_phys, sdma->regs + SDMA_H_C0PTR);
+       writel_relaxed(ccb_phys, sdma->regs + SDMA_H_C0PTR);
  
        /* Set bits of CONFIG register with given context switching mode */
-       __raw_writel(SDMA_H_CONFIG_CSM, sdma->regs + SDMA_H_CONFIG);
+       writel_relaxed(SDMA_H_CONFIG_CSM, sdma->regs + SDMA_H_CONFIG);
  
        /* Initializes channel's priorities */
        sdma_set_channel_priority(&sdma->channel[0], 7);
@@@ -1367,6 -1357,7 +1356,7 @@@ static int __init sdma_probe(struct pla
                spin_lock_init(&sdmac->lock);
  
                sdmac->chan.device = &sdma->dma_device;
+               dma_cookie_init(&sdmac->chan);
                sdmac->channel = i;
  
                /*
                sdma_add_scripts(sdma, pdata->script_addrs);
  
        if (pdata) {
-               sdma_get_firmware(sdma, pdata->fw_name);
+               ret = sdma_get_firmware(sdma, pdata->fw_name);
+               if (ret)
+                       dev_warn(&pdev->dev, "failed to get firmware from platform data\n");
        } else {
                /*
                 * Because that device tree does not encode ROM script address,
                 */
                ret = of_property_read_string(np, "fsl,sdma-ram-script-name",
                                              &fw_name);
-               if (ret) {
-                       dev_err(&pdev->dev, "failed to get firmware name\n");
-                       goto err_init;
-               }
-               ret = sdma_get_firmware(sdma, fw_name);
-               if (ret) {
-                       dev_err(&pdev->dev, "failed to get firmware\n");
-                       goto err_init;
+               if (ret)
+                       dev_warn(&pdev->dev, "failed to get firmware name\n");
+               else {
+                       ret = sdma_get_firmware(sdma, fw_name);
+                       if (ret)
+                               dev_warn(&pdev->dev, "failed to get firmware from device tree\n");
                }
        }
  
diff --combined drivers/dma/iop-adma.c
index faf88b7e1e71d4d0385b9f1c9038429a774ff826,4499f88789bceb4c56d6fd20801f17b6d7f5458d..da6c4c2c066a96b68cdb0765ba4e017112f1c7a6
@@@ -36,6 -36,8 +36,8 @@@
  
  #include <mach/adma.h>
  
+ #include "dmaengine.h"
  #define to_iop_adma_chan(chan) container_of(chan, struct iop_adma_chan, common)
  #define to_iop_adma_device(dev) \
        container_of(dev, struct iop_adma_device, common)
@@@ -317,7 -319,7 +319,7 @@@ static void __iop_adma_slot_cleanup(str
        }
  
        if (cookie > 0) {
-               iop_chan->completed_cookie = cookie;
+               iop_chan->common.completed_cookie = cookie;
                pr_debug("\tcompleted cookie %d\n", cookie);
        }
  }
@@@ -438,18 -440,6 +440,6 @@@ retry
        return NULL;
  }
  
- static dma_cookie_t
- iop_desc_assign_cookie(struct iop_adma_chan *iop_chan,
-       struct iop_adma_desc_slot *desc)
- {
-       dma_cookie_t cookie = iop_chan->common.cookie;
-       cookie++;
-       if (cookie < 0)
-               cookie = 1;
-       iop_chan->common.cookie = desc->async_tx.cookie = cookie;
-       return cookie;
- }
  static void iop_adma_check_threshold(struct iop_adma_chan *iop_chan)
  {
        dev_dbg(iop_chan->device->common.dev, "pending: %d\n",
@@@ -477,7 -467,7 +467,7 @@@ iop_adma_tx_submit(struct dma_async_tx_
        slots_per_op = grp_start->slots_per_op;
  
        spin_lock_bh(&iop_chan->lock);
-       cookie = iop_desc_assign_cookie(iop_chan, sw_desc);
+       cookie = dma_cookie_assign(tx);
  
        old_chain_tail = list_entry(iop_chan->chain.prev,
                struct iop_adma_desc_slot, chain_node);
@@@ -904,24 -894,15 +894,15 @@@ static enum dma_status iop_adma_status(
                                        struct dma_tx_state *txstate)
  {
        struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
-       dma_cookie_t last_used;
-       dma_cookie_t last_complete;
-       enum dma_status ret;
-       last_used = chan->cookie;
-       last_complete = iop_chan->completed_cookie;
-       dma_set_tx_state(txstate, last_complete, last_used, 0);
-       ret = dma_async_is_complete(cookie, last_complete, last_used);
+       int ret;
+       ret = dma_cookie_status(chan, cookie, txstate);
        if (ret == DMA_SUCCESS)
                return ret;
  
        iop_adma_slot_cleanup(iop_chan);
  
-       last_used = chan->cookie;
-       last_complete = iop_chan->completed_cookie;
-       dma_set_tx_state(txstate, last_complete, last_used, 0);
-       return dma_async_is_complete(cookie, last_complete, last_used);
+       return dma_cookie_status(chan, cookie, txstate);
  }
  
  static irqreturn_t iop_adma_eot_handler(int irq, void *data)
@@@ -1482,7 -1463,7 +1463,7 @@@ static int __devinit iop_adma_probe(str
                goto err_free_adev;
        }
  
 -      dev_dbg(&pdev->dev, "%s: allocted descriptor pool virt %p phys %p\n",
 +      dev_dbg(&pdev->dev, "%s: allocated descriptor pool virt %p phys %p\n",
                __func__, adev->dma_desc_pool_virt,
                (void *) adev->dma_desc_pool);
  
        INIT_LIST_HEAD(&iop_chan->chain);
        INIT_LIST_HEAD(&iop_chan->all_slots);
        iop_chan->common.device = dma_dev;
+       dma_cookie_init(&iop_chan->common);
        list_add_tail(&iop_chan->common.device_node, &dma_dev->channels);
  
        if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
@@@ -1642,16 -1624,12 +1624,12 @@@ static void iop_chan_start_null_memcpy(
                iop_desc_set_dest_addr(grp_start, iop_chan, 0);
                iop_desc_set_memcpy_src_addr(grp_start, 0);
  
-               cookie = iop_chan->common.cookie;
-               cookie++;
-               if (cookie <= 1)
-                       cookie = 2;
+               cookie = dma_cookie_assign(&sw_desc->async_tx);
  
                /* initialize the completed cookie to be less than
                 * the most recently used cookie
                 */
-               iop_chan->completed_cookie = cookie - 1;
-               iop_chan->common.cookie = sw_desc->async_tx.cookie = cookie;
+               iop_chan->common.completed_cookie = cookie - 1;
  
                /* channel should not be busy */
                BUG_ON(iop_chan_is_busy(iop_chan));
@@@ -1699,16 -1677,12 +1677,12 @@@ static void iop_chan_start_null_xor(str
                iop_desc_set_xor_src_addr(grp_start, 0, 0);
                iop_desc_set_xor_src_addr(grp_start, 1, 0);
  
-               cookie = iop_chan->common.cookie;
-               cookie++;
-               if (cookie <= 1)
-                       cookie = 2;
+               cookie = dma_cookie_assign(&sw_desc->async_tx);
  
                /* initialize the completed cookie to be less than
                 * the most recently used cookie
                 */
-               iop_chan->completed_cookie = cookie - 1;
-               iop_chan->common.cookie = sw_desc->async_tx.cookie = cookie;
+               iop_chan->common.completed_cookie = cookie - 1;
  
                /* channel should not be busy */
                BUG_ON(iop_chan_is_busy(iop_chan));
diff --combined drivers/dma/pl330.c
index 16b66c827f19984c47401b89d70338570c446f18,87d752a77f5e0395d3ed4426de1ee9f2657e38e8..282caf118be819c5e9257754a369efd292607951
@@@ -1,4 -1,6 +1,6 @@@
- /* linux/drivers/dma/pl330.c
+ /*
+  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+  *            http://www.samsung.com
   *
   * Copyright (C) 2010 Samsung Electronics Co. Ltd.
   *    Jaswinder Singh <jassi.brar@samsung.com>
   * (at your option) any later version.
   */
  
- #include <linux/io.h>
- #include <linux/init.h>
- #include <linux/slab.h>
- #include <linux/module.h>
- #include <linux/dmaengine.h>
- #include <linux/interrupt.h>
- #include <linux/amba/bus.h>
- #include <linux/amba/pl330.h>
- #include <linux/pm_runtime.h>
- #include <linux/scatterlist.h>
- #include <linux/of.h>
+ #include <linux/kernel.h>
+ #include <linux/io.h>
+ #include <linux/init.h>
+ #include <linux/slab.h>
+ #include <linux/module.h>
+ #include <linux/string.h>
+ #include <linux/delay.h>
+ #include <linux/interrupt.h>
+ #include <linux/dma-mapping.h>
+ #include <linux/dmaengine.h>
+ #include <linux/interrupt.h>
+ #include <linux/amba/bus.h>
+ #include <linux/amba/pl330.h>
+ #include <linux/pm_runtime.h>
+ #include <linux/scatterlist.h>
+ #include <linux/of.h>
+ #include "dmaengine.h"
+ #define PL330_MAX_CHAN                8
+ #define PL330_MAX_IRQS                32
+ #define PL330_MAX_PERI                32
+ enum pl330_srccachectrl {
+       SCCTRL0,        /* Noncacheable and nonbufferable */
+       SCCTRL1,        /* Bufferable only */
+       SCCTRL2,        /* Cacheable, but do not allocate */
+       SCCTRL3,        /* Cacheable and bufferable, but do not allocate */
+       SINVALID1,
+       SINVALID2,
+       SCCTRL6,        /* Cacheable write-through, allocate on reads only */
+       SCCTRL7,        /* Cacheable write-back, allocate on reads only */
+ };
+ enum pl330_dstcachectrl {
+       DCCTRL0,        /* Noncacheable and nonbufferable */
+       DCCTRL1,        /* Bufferable only */
+       DCCTRL2,        /* Cacheable, but do not allocate */
+       DCCTRL3,        /* Cacheable and bufferable, but do not allocate */
 -      DINVALID1 = 8,
++      DINVALID1,      /* AWCACHE = 0x1000 */
+       DINVALID2,
+       DCCTRL6,        /* Cacheable write-through, allocate on writes only */
+       DCCTRL7,        /* Cacheable write-back, allocate on writes only */
+ };
+ enum pl330_byteswap {
+       SWAP_NO,
+       SWAP_2,
+       SWAP_4,
+       SWAP_8,
+       SWAP_16,
+ };
+ enum pl330_reqtype {
+       MEMTOMEM,
+       MEMTODEV,
+       DEVTOMEM,
+       DEVTODEV,
+ };
+ /* Register and Bit field Definitions */
+ #define DS                    0x0
+ #define DS_ST_STOP            0x0
+ #define DS_ST_EXEC            0x1
+ #define DS_ST_CMISS           0x2
+ #define DS_ST_UPDTPC          0x3
+ #define DS_ST_WFE             0x4
+ #define DS_ST_ATBRR           0x5
+ #define DS_ST_QBUSY           0x6
+ #define DS_ST_WFP             0x7
+ #define DS_ST_KILL            0x8
+ #define DS_ST_CMPLT           0x9
+ #define DS_ST_FLTCMP          0xe
+ #define DS_ST_FAULT           0xf
+ #define DPC                   0x4
+ #define INTEN                 0x20
+ #define ES                    0x24
+ #define INTSTATUS             0x28
+ #define INTCLR                        0x2c
+ #define FSM                   0x30
+ #define FSC                   0x34
+ #define FTM                   0x38
+ #define _FTC                  0x40
+ #define FTC(n)                        (_FTC + (n)*0x4)
+ #define _CS                   0x100
+ #define CS(n)                 (_CS + (n)*0x8)
+ #define CS_CNS                        (1 << 21)
+ #define _CPC                  0x104
+ #define CPC(n)                        (_CPC + (n)*0x8)
+ #define _SA                   0x400
+ #define SA(n)                 (_SA + (n)*0x20)
+ #define _DA                   0x404
+ #define DA(n)                 (_DA + (n)*0x20)
+ #define _CC                   0x408
+ #define CC(n)                 (_CC + (n)*0x20)
+ #define CC_SRCINC             (1 << 0)
+ #define CC_DSTINC             (1 << 14)
+ #define CC_SRCPRI             (1 << 8)
+ #define CC_DSTPRI             (1 << 22)
+ #define CC_SRCNS              (1 << 9)
+ #define CC_DSTNS              (1 << 23)
+ #define CC_SRCIA              (1 << 10)
+ #define CC_DSTIA              (1 << 24)
+ #define CC_SRCBRSTLEN_SHFT    4
+ #define CC_DSTBRSTLEN_SHFT    18
+ #define CC_SRCBRSTSIZE_SHFT   1
+ #define CC_DSTBRSTSIZE_SHFT   15
+ #define CC_SRCCCTRL_SHFT      11
+ #define CC_SRCCCTRL_MASK      0x7
+ #define CC_DSTCCTRL_SHFT      25
+ #define CC_DRCCCTRL_MASK      0x7
+ #define CC_SWAP_SHFT          28
+ #define _LC0                  0x40c
+ #define LC0(n)                        (_LC0 + (n)*0x20)
+ #define _LC1                  0x410
+ #define LC1(n)                        (_LC1 + (n)*0x20)
+ #define DBGSTATUS             0xd00
+ #define DBG_BUSY              (1 << 0)
+ #define DBGCMD                        0xd04
+ #define DBGINST0              0xd08
+ #define DBGINST1              0xd0c
+ #define CR0                   0xe00
+ #define CR1                   0xe04
+ #define CR2                   0xe08
+ #define CR3                   0xe0c
+ #define CR4                   0xe10
+ #define CRD                   0xe14
+ #define PERIPH_ID             0xfe0
+ #define PERIPH_REV_SHIFT      20
+ #define PERIPH_REV_MASK               0xf
+ #define PERIPH_REV_R0P0               0
+ #define PERIPH_REV_R1P0               1
+ #define PERIPH_REV_R1P1               2
+ #define PCELL_ID              0xff0
+ #define CR0_PERIPH_REQ_SET    (1 << 0)
+ #define CR0_BOOT_EN_SET               (1 << 1)
+ #define CR0_BOOT_MAN_NS               (1 << 2)
+ #define CR0_NUM_CHANS_SHIFT   4
+ #define CR0_NUM_CHANS_MASK    0x7
+ #define CR0_NUM_PERIPH_SHIFT  12
+ #define CR0_NUM_PERIPH_MASK   0x1f
+ #define CR0_NUM_EVENTS_SHIFT  17
+ #define CR0_NUM_EVENTS_MASK   0x1f
+ #define CR1_ICACHE_LEN_SHIFT  0
+ #define CR1_ICACHE_LEN_MASK   0x7
+ #define CR1_NUM_ICACHELINES_SHIFT     4
+ #define CR1_NUM_ICACHELINES_MASK      0xf
+ #define CRD_DATA_WIDTH_SHIFT  0
+ #define CRD_DATA_WIDTH_MASK   0x7
+ #define CRD_WR_CAP_SHIFT      4
+ #define CRD_WR_CAP_MASK               0x7
+ #define CRD_WR_Q_DEP_SHIFT    8
+ #define CRD_WR_Q_DEP_MASK     0xf
+ #define CRD_RD_CAP_SHIFT      12
+ #define CRD_RD_CAP_MASK               0x7
+ #define CRD_RD_Q_DEP_SHIFT    16
+ #define CRD_RD_Q_DEP_MASK     0xf
+ #define CRD_DATA_BUFF_SHIFT   20
+ #define CRD_DATA_BUFF_MASK    0x3ff
+ #define PART                  0x330
+ #define DESIGNER              0x41
+ #define REVISION              0x0
+ #define INTEG_CFG             0x0
+ #define PERIPH_ID_VAL         ((PART << 0) | (DESIGNER << 12))
+ #define PCELL_ID_VAL          0xb105f00d
+ #define PL330_STATE_STOPPED           (1 << 0)
+ #define PL330_STATE_EXECUTING         (1 << 1)
+ #define PL330_STATE_WFE                       (1 << 2)
+ #define PL330_STATE_FAULTING          (1 << 3)
+ #define PL330_STATE_COMPLETING                (1 << 4)
+ #define PL330_STATE_WFP                       (1 << 5)
+ #define PL330_STATE_KILLING           (1 << 6)
+ #define PL330_STATE_FAULT_COMPLETING  (1 << 7)
+ #define PL330_STATE_CACHEMISS         (1 << 8)
+ #define PL330_STATE_UPDTPC            (1 << 9)
+ #define PL330_STATE_ATBARRIER         (1 << 10)
+ #define PL330_STATE_QUEUEBUSY         (1 << 11)
+ #define PL330_STATE_INVALID           (1 << 15)
+ #define PL330_STABLE_STATES (PL330_STATE_STOPPED | PL330_STATE_EXECUTING \
+                               | PL330_STATE_WFE | PL330_STATE_FAULTING)
+ #define CMD_DMAADDH           0x54
+ #define CMD_DMAEND            0x00
+ #define CMD_DMAFLUSHP         0x35
+ #define CMD_DMAGO             0xa0
+ #define CMD_DMALD             0x04
+ #define CMD_DMALDP            0x25
+ #define CMD_DMALP             0x20
+ #define CMD_DMALPEND          0x28
+ #define CMD_DMAKILL           0x01
+ #define CMD_DMAMOV            0xbc
+ #define CMD_DMANOP            0x18
+ #define CMD_DMARMB            0x12
+ #define CMD_DMASEV            0x34
+ #define CMD_DMAST             0x08
+ #define CMD_DMASTP            0x29
+ #define CMD_DMASTZ            0x0c
+ #define CMD_DMAWFE            0x36
+ #define CMD_DMAWFP            0x30
+ #define CMD_DMAWMB            0x13
+ #define SZ_DMAADDH            3
+ #define SZ_DMAEND             1
+ #define SZ_DMAFLUSHP          2
+ #define SZ_DMALD              1
+ #define SZ_DMALDP             2
+ #define SZ_DMALP              2
+ #define SZ_DMALPEND           2
+ #define SZ_DMAKILL            1
+ #define SZ_DMAMOV             6
+ #define SZ_DMANOP             1
+ #define SZ_DMARMB             1
+ #define SZ_DMASEV             2
+ #define SZ_DMAST              1
+ #define SZ_DMASTP             2
+ #define SZ_DMASTZ             1
+ #define SZ_DMAWFE             2
+ #define SZ_DMAWFP             2
+ #define SZ_DMAWMB             1
+ #define SZ_DMAGO              6
+ #define BRST_LEN(ccr)         ((((ccr) >> CC_SRCBRSTLEN_SHFT) & 0xf) + 1)
+ #define BRST_SIZE(ccr)                (1 << (((ccr) >> CC_SRCBRSTSIZE_SHFT) & 0x7))
+ #define BYTE_TO_BURST(b, ccr) ((b) / BRST_SIZE(ccr) / BRST_LEN(ccr))
+ #define BURST_TO_BYTE(c, ccr) ((c) * BRST_SIZE(ccr) * BRST_LEN(ccr))
+ /*
+  * With 256 bytes, we can do more than 2.5MB and 5MB xfers per req
+  * at 1byte/burst for P<->M and M<->M respectively.
+  * For typical scenario, at 1word/burst, 10MB and 20MB xfers per req
+  * should be enough for P<->M and M<->M respectively.
+  */
+ #define MCODE_BUFF_PER_REQ    256
+ /* If the _pl330_req is available to the client */
+ #define IS_FREE(req)  (*((u8 *)((req)->mc_cpu)) == CMD_DMAEND)
+ /* Use this _only_ to wait on transient states */
+ #define UNTIL(t, s)   while (!(_state(t) & (s))) cpu_relax();
+ #ifdef PL330_DEBUG_MCGEN
+ static unsigned cmd_line;
+ #define PL330_DBGCMD_DUMP(off, x...)  do { \
+                                               printk("%x:", cmd_line); \
+                                               printk(x); \
+                                               cmd_line += off; \
+                                       } while (0)
+ #define PL330_DBGMC_START(addr)               (cmd_line = addr)
+ #else
+ #define PL330_DBGCMD_DUMP(off, x...)  do {} while (0)
+ #define PL330_DBGMC_START(addr)               do {} while (0)
+ #endif
+ /* The number of default descriptors */
+ #define NR_DEFAULT_DESC       16
+ /* Populated by the PL330 core driver for DMA API driver's info */
+ struct pl330_config {
+       u32     periph_id;
+       u32     pcell_id;
+ #define DMAC_MODE_NS  (1 << 0)
+       unsigned int    mode;
+       unsigned int    data_bus_width:10; /* In number of bits */
+       unsigned int    data_buf_dep:10;
+       unsigned int    num_chan:4;
+       unsigned int    num_peri:6;
+       u32             peri_ns;
+       unsigned int    num_events:6;
+       u32             irq_ns;
+ };
+ /* Handle to the DMAC provided to the PL330 core */
+ struct pl330_info {
+       /* Owning device */
+       struct device *dev;
+       /* Size of MicroCode buffers for each channel. */
+       unsigned mcbufsz;
+       /* ioremap'ed address of PL330 registers. */
+       void __iomem    *base;
+       /* Client can freely use it. */
+       void    *client_data;
+       /* PL330 core data, Client must not touch it. */
+       void    *pl330_data;
+       /* Populated by the PL330 core driver during pl330_add */
+       struct pl330_config     pcfg;
+       /*
+        * If the DMAC has some reset mechanism, then the
+        * client may want to provide pointer to the method.
+        */
+       void (*dmac_reset)(struct pl330_info *pi);
+ };
+ /**
+  * Request Configuration.
+  * The PL330 core does not modify this and uses the last
+  * working configuration if the request doesn't provide any.
+  *
+  * The Client may want to provide this info only for the
+  * first request and a request with new settings.
+  */
+ struct pl330_reqcfg {
+       /* Address Incrementing */
+       unsigned dst_inc:1;
+       unsigned src_inc:1;
+       /*
+        * For now, the SRC & DST protection levels
+        * and burst size/length are assumed same.
+        */
+       bool nonsecure;
+       bool privileged;
+       bool insnaccess;
+       unsigned brst_len:5;
+       unsigned brst_size:3; /* in power of 2 */
+       enum pl330_dstcachectrl dcctl;
+       enum pl330_srccachectrl scctl;
+       enum pl330_byteswap swap;
+       struct pl330_config *pcfg;
+ };
+ /*
+  * One cycle of DMAC operation.
+  * There may be more than one xfer in a request.
+  */
+ struct pl330_xfer {
+       u32 src_addr;
+       u32 dst_addr;
+       /* Size to xfer */
+       u32 bytes;
+       /*
+        * Pointer to next xfer in the list.
+        * The last xfer in the req must point to NULL.
+        */
+       struct pl330_xfer *next;
+ };
+ /* The xfer callbacks are made with one of these arguments. */
+ enum pl330_op_err {
+       /* The all xfers in the request were success. */
+       PL330_ERR_NONE,
+       /* If req aborted due to global error. */
+       PL330_ERR_ABORT,
+       /* If req failed due to problem with Channel. */
+       PL330_ERR_FAIL,
+ };
+ /* A request defining Scatter-Gather List ending with NULL xfer. */
+ struct pl330_req {
+       enum pl330_reqtype rqtype;
+       /* Index of peripheral for the xfer. */
+       unsigned peri:5;
+       /* Unique token for this xfer, set by the client. */
+       void *token;
+       /* Callback to be called after xfer. */
+       void (*xfer_cb)(void *token, enum pl330_op_err err);
+       /* If NULL, req will be done at last set parameters. */
+       struct pl330_reqcfg *cfg;
+       /* Pointer to first xfer in the request. */
+       struct pl330_xfer *x;
+ };
+ /*
+  * To know the status of the channel and DMAC, the client
+  * provides a pointer to this structure. The PL330 core
+  * fills it with current information.
+  */
+ struct pl330_chanstatus {
+       /*
+        * If the DMAC engine halted due to some error,
+        * the client should remove-add DMAC.
+        */
+       bool dmac_halted;
+       /*
+        * If channel is halted due to some error,
+        * the client should ABORT/FLUSH and START the channel.
+        */
+       bool faulting;
+       /* Location of last load */
+       u32 src_addr;
+       /* Location of last store */
+       u32 dst_addr;
+       /*
+        * Pointer to the currently active req, NULL if channel is
+        * inactive, even though the requests may be present.
+        */
+       struct pl330_req *top_req;
+       /* Pointer to req waiting second in the queue if any. */
+       struct pl330_req *wait_req;
+ };
+ enum pl330_chan_op {
+       /* Start the channel */
+       PL330_OP_START,
+       /* Abort the active xfer */
+       PL330_OP_ABORT,
+       /* Stop xfer and flush queue */
+       PL330_OP_FLUSH,
+ };
+ struct _xfer_spec {
+       u32 ccr;
+       struct pl330_req *r;
+       struct pl330_xfer *x;
+ };
+ enum dmamov_dst {
+       SAR = 0,
+       CCR,
+       DAR,
+ };
+ enum pl330_dst {
+       SRC = 0,
+       DST,
+ };
+ enum pl330_cond {
+       SINGLE,
+       BURST,
+       ALWAYS,
+ };
+ struct _pl330_req {
+       u32 mc_bus;
+       void *mc_cpu;
+       /* Number of bytes taken to setup MC for the req */
+       u32 mc_len;
+       struct pl330_req *r;
+       /* Hook to attach to DMAC's list of reqs with due callback */
+       struct list_head rqd;
+ };
+ /* ToBeDone for tasklet */
+ struct _pl330_tbd {
+       bool reset_dmac;
+       bool reset_mngr;
+       u8 reset_chan;
+ };
+ /* A DMAC Thread */
+ struct pl330_thread {
+       u8 id;
+       int ev;
+       /* If the channel is not yet acquired by any client */
+       bool free;
+       /* Parent DMAC */
+       struct pl330_dmac *dmac;
+       /* Only two at a time */
+       struct _pl330_req req[2];
+       /* Index of the last enqueued request */
+       unsigned lstenq;
+       /* Index of the last submitted request or -1 if the DMA is stopped */
+       int req_running;
+ };
+ enum pl330_dmac_state {
+       UNINIT,
+       INIT,
+       DYING,
+ };
+ /* A DMAC */
+ struct pl330_dmac {
+       spinlock_t              lock;
+       /* Holds list of reqs with due callbacks */
+       struct list_head        req_done;
+       /* Pointer to platform specific stuff */
+       struct pl330_info       *pinfo;
+       /* Maximum possible events/irqs */
+       int                     events[32];
+       /* BUS address of MicroCode buffer */
+       u32                     mcode_bus;
+       /* CPU address of MicroCode buffer */
+       void                    *mcode_cpu;
+       /* List of all Channel threads */
+       struct pl330_thread     *channels;
+       /* Pointer to the MANAGER thread */
+       struct pl330_thread     *manager;
+       /* To handle bad news in interrupt */
+       struct tasklet_struct   tasks;
+       struct _pl330_tbd       dmac_tbd;
+       /* State of DMAC operation */
+       enum pl330_dmac_state   state;
+ };
+ enum desc_status {
+       /* In the DMAC pool */
+       FREE,
+       /*
+        * Allocted to some channel during prep_xxx
+        * Also may be sitting on the work_list.
+        */
+       PREP,
+       /*
+        * Sitting on the work_list and already submitted
+        * to the PL330 core. Not more than two descriptors
+        * of a channel can be BUSY at any time.
+        */
+       BUSY,
+       /*
+        * Sitting on the channel work_list but xfer done
+        * by PL330 core
+        */
+       DONE,
+ };
+ struct dma_pl330_chan {
+       /* Schedule desc completion */
+       struct tasklet_struct task;
+       /* DMA-Engine Channel */
+       struct dma_chan chan;
+       /* List of to be xfered descriptors */
+       struct list_head work_list;
+       /* Pointer to the DMAC that manages this channel,
+        * NULL if the channel is available to be acquired.
+        * As the parent, this DMAC also provides descriptors
+        * to the channel.
+        */
+       struct dma_pl330_dmac *dmac;
+       /* To protect channel manipulation */
+       spinlock_t lock;
+       /* Token of a hardware channel thread of PL330 DMAC
+        * NULL if the channel is available to be acquired.
+        */
+       void *pl330_chid;
+       /* For D-to-M and M-to-D channels */
+       int burst_sz; /* the peripheral fifo width */
+       int burst_len; /* the number of burst */
+       dma_addr_t fifo_addr;
+       /* for cyclic capability */
+       bool cyclic;
+ };
+ struct dma_pl330_dmac {
+       struct pl330_info pif;
+       /* DMA-Engine Device */
+       struct dma_device ddma;
+       /* Pool of descriptors available for the DMAC's channels */
+       struct list_head desc_pool;
+       /* To protect desc_pool manipulation */
+       spinlock_t pool_lock;
+       /* Peripheral channels connected to this DMAC */
+       struct dma_pl330_chan *peripherals; /* keep at end */
+       struct clk *clk;
+ };
+ struct dma_pl330_desc {
+       /* To attach to a queue as child */
+       struct list_head node;
+       /* Descriptor for the DMA Engine API */
+       struct dma_async_tx_descriptor txd;
+       /* Xfer for PL330 core */
+       struct pl330_xfer px;
+       struct pl330_reqcfg rqcfg;
+       struct pl330_req req;
+       enum desc_status status;
+       /* The channel which currently holds this desc */
+       struct dma_pl330_chan *pchan;
+ };
+ static inline void _callback(struct pl330_req *r, enum pl330_op_err err)
+ {
+       if (r && r->xfer_cb)
+               r->xfer_cb(r->token, err);
+ }
+ static inline bool _queue_empty(struct pl330_thread *thrd)
+ {
+       return (IS_FREE(&thrd->req[0]) && IS_FREE(&thrd->req[1]))
+               ? true : false;
+ }
+ static inline bool _queue_full(struct pl330_thread *thrd)
+ {
+       return (IS_FREE(&thrd->req[0]) || IS_FREE(&thrd->req[1]))
+               ? false : true;
+ }
+ static inline bool is_manager(struct pl330_thread *thrd)
+ {
+       struct pl330_dmac *pl330 = thrd->dmac;
+       /* MANAGER is indexed at the end */
+       if (thrd->id == pl330->pinfo->pcfg.num_chan)
+               return true;
+       else
+               return false;
+ }
+ /* If manager of the thread is in Non-Secure mode */
+ static inline bool _manager_ns(struct pl330_thread *thrd)
+ {
+       struct pl330_dmac *pl330 = thrd->dmac;
+       return (pl330->pinfo->pcfg.mode & DMAC_MODE_NS) ? true : false;
+ }
+ static inline u32 get_id(struct pl330_info *pi, u32 off)
+ {
+       void __iomem *regs = pi->base;
+       u32 id = 0;
+       id |= (readb(regs + off + 0x0) << 0);
+       id |= (readb(regs + off + 0x4) << 8);
+       id |= (readb(regs + off + 0x8) << 16);
+       id |= (readb(regs + off + 0xc) << 24);
+       return id;
+ }
+ static inline u32 get_revision(u32 periph_id)
+ {
+       return (periph_id >> PERIPH_REV_SHIFT) & PERIPH_REV_MASK;
+ }
+ static inline u32 _emit_ADDH(unsigned dry_run, u8 buf[],
+               enum pl330_dst da, u16 val)
+ {
+       if (dry_run)
+               return SZ_DMAADDH;
+       buf[0] = CMD_DMAADDH;
+       buf[0] |= (da << 1);
+       *((u16 *)&buf[1]) = val;
+       PL330_DBGCMD_DUMP(SZ_DMAADDH, "\tDMAADDH %s %u\n",
+               da == 1 ? "DA" : "SA", val);
+       return SZ_DMAADDH;
+ }
+ static inline u32 _emit_END(unsigned dry_run, u8 buf[])
+ {
+       if (dry_run)
+               return SZ_DMAEND;
+       buf[0] = CMD_DMAEND;
+       PL330_DBGCMD_DUMP(SZ_DMAEND, "\tDMAEND\n");
+       return SZ_DMAEND;
+ }
+ static inline u32 _emit_FLUSHP(unsigned dry_run, u8 buf[], u8 peri)
+ {
+       if (dry_run)
+               return SZ_DMAFLUSHP;
+       buf[0] = CMD_DMAFLUSHP;
+       peri &= 0x1f;
+       peri <<= 3;
+       buf[1] = peri;
+       PL330_DBGCMD_DUMP(SZ_DMAFLUSHP, "\tDMAFLUSHP %u\n", peri >> 3);
+       return SZ_DMAFLUSHP;
+ }
+ static inline u32 _emit_LD(unsigned dry_run, u8 buf[],        enum pl330_cond cond)
+ {
+       if (dry_run)
+               return SZ_DMALD;
+       buf[0] = CMD_DMALD;
+       if (cond == SINGLE)
+               buf[0] |= (0 << 1) | (1 << 0);
+       else if (cond == BURST)
+               buf[0] |= (1 << 1) | (1 << 0);
+       PL330_DBGCMD_DUMP(SZ_DMALD, "\tDMALD%c\n",
+               cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'));
+       return SZ_DMALD;
+ }
+ static inline u32 _emit_LDP(unsigned dry_run, u8 buf[],
+               enum pl330_cond cond, u8 peri)
+ {
+       if (dry_run)
+               return SZ_DMALDP;
+       buf[0] = CMD_DMALDP;
+       if (cond == BURST)
+               buf[0] |= (1 << 1);
+       peri &= 0x1f;
+       peri <<= 3;
+       buf[1] = peri;
+       PL330_DBGCMD_DUMP(SZ_DMALDP, "\tDMALDP%c %u\n",
+               cond == SINGLE ? 'S' : 'B', peri >> 3);
+       return SZ_DMALDP;
+ }
+ static inline u32 _emit_LP(unsigned dry_run, u8 buf[],
+               unsigned loop, u8 cnt)
+ {
+       if (dry_run)
+               return SZ_DMALP;
+       buf[0] = CMD_DMALP;
+       if (loop)
+               buf[0] |= (1 << 1);
+       cnt--; /* DMAC increments by 1 internally */
+       buf[1] = cnt;
+       PL330_DBGCMD_DUMP(SZ_DMALP, "\tDMALP_%c %u\n", loop ? '1' : '0', cnt);
+       return SZ_DMALP;
+ }
+ struct _arg_LPEND {
+       enum pl330_cond cond;
+       bool forever;
+       unsigned loop;
+       u8 bjump;
+ };
+ static inline u32 _emit_LPEND(unsigned dry_run, u8 buf[],
+               const struct _arg_LPEND *arg)
+ {
+       enum pl330_cond cond = arg->cond;
+       bool forever = arg->forever;
+       unsigned loop = arg->loop;
+       u8 bjump = arg->bjump;
+       if (dry_run)
+               return SZ_DMALPEND;
+       buf[0] = CMD_DMALPEND;
+       if (loop)
+               buf[0] |= (1 << 2);
+       if (!forever)
+               buf[0] |= (1 << 4);
+       if (cond == SINGLE)
+               buf[0] |= (0 << 1) | (1 << 0);
+       else if (cond == BURST)
+               buf[0] |= (1 << 1) | (1 << 0);
+       buf[1] = bjump;
+       PL330_DBGCMD_DUMP(SZ_DMALPEND, "\tDMALP%s%c_%c bjmpto_%x\n",
+                       forever ? "FE" : "END",
+                       cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'),
+                       loop ? '1' : '0',
+                       bjump);
+       return SZ_DMALPEND;
+ }
+ static inline u32 _emit_KILL(unsigned dry_run, u8 buf[])
+ {
+       if (dry_run)
+               return SZ_DMAKILL;
+       buf[0] = CMD_DMAKILL;
+       return SZ_DMAKILL;
+ }
+ static inline u32 _emit_MOV(unsigned dry_run, u8 buf[],
+               enum dmamov_dst dst, u32 val)
+ {
+       if (dry_run)
+               return SZ_DMAMOV;
+       buf[0] = CMD_DMAMOV;
+       buf[1] = dst;
+       *((u32 *)&buf[2]) = val;
+       PL330_DBGCMD_DUMP(SZ_DMAMOV, "\tDMAMOV %s 0x%x\n",
+               dst == SAR ? "SAR" : (dst == DAR ? "DAR" : "CCR"), val);
+       return SZ_DMAMOV;
+ }
+ static inline u32 _emit_NOP(unsigned dry_run, u8 buf[])
+ {
+       if (dry_run)
+               return SZ_DMANOP;
+       buf[0] = CMD_DMANOP;
+       PL330_DBGCMD_DUMP(SZ_DMANOP, "\tDMANOP\n");
+       return SZ_DMANOP;
+ }
+ static inline u32 _emit_RMB(unsigned dry_run, u8 buf[])
+ {
+       if (dry_run)
+               return SZ_DMARMB;
+       buf[0] = CMD_DMARMB;
+       PL330_DBGCMD_DUMP(SZ_DMARMB, "\tDMARMB\n");
+       return SZ_DMARMB;
+ }
+ static inline u32 _emit_SEV(unsigned dry_run, u8 buf[], u8 ev)
+ {
+       if (dry_run)
+               return SZ_DMASEV;
+       buf[0] = CMD_DMASEV;
+       ev &= 0x1f;
+       ev <<= 3;
+       buf[1] = ev;
+       PL330_DBGCMD_DUMP(SZ_DMASEV, "\tDMASEV %u\n", ev >> 3);
+       return SZ_DMASEV;
+ }
+ static inline u32 _emit_ST(unsigned dry_run, u8 buf[], enum pl330_cond cond)
+ {
+       if (dry_run)
+               return SZ_DMAST;
+       buf[0] = CMD_DMAST;
+       if (cond == SINGLE)
+               buf[0] |= (0 << 1) | (1 << 0);
+       else if (cond == BURST)
+               buf[0] |= (1 << 1) | (1 << 0);
+       PL330_DBGCMD_DUMP(SZ_DMAST, "\tDMAST%c\n",
+               cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'));
+       return SZ_DMAST;
+ }
+ static inline u32 _emit_STP(unsigned dry_run, u8 buf[],
+               enum pl330_cond cond, u8 peri)
+ {
+       if (dry_run)
+               return SZ_DMASTP;
+       buf[0] = CMD_DMASTP;
+       if (cond == BURST)
+               buf[0] |= (1 << 1);
+       peri &= 0x1f;
+       peri <<= 3;
+       buf[1] = peri;
+       PL330_DBGCMD_DUMP(SZ_DMASTP, "\tDMASTP%c %u\n",
+               cond == SINGLE ? 'S' : 'B', peri >> 3);
+       return SZ_DMASTP;
+ }
+ static inline u32 _emit_STZ(unsigned dry_run, u8 buf[])
+ {
+       if (dry_run)
+               return SZ_DMASTZ;
+       buf[0] = CMD_DMASTZ;
+       PL330_DBGCMD_DUMP(SZ_DMASTZ, "\tDMASTZ\n");
+       return SZ_DMASTZ;
+ }
+ static inline u32 _emit_WFE(unsigned dry_run, u8 buf[], u8 ev,
+               unsigned invalidate)
+ {
+       if (dry_run)
+               return SZ_DMAWFE;
+       buf[0] = CMD_DMAWFE;
+       ev &= 0x1f;
+       ev <<= 3;
+       buf[1] = ev;
+       if (invalidate)
+               buf[1] |= (1 << 1);
+       PL330_DBGCMD_DUMP(SZ_DMAWFE, "\tDMAWFE %u%s\n",
+               ev >> 3, invalidate ? ", I" : "");
+       return SZ_DMAWFE;
+ }
+ static inline u32 _emit_WFP(unsigned dry_run, u8 buf[],
+               enum pl330_cond cond, u8 peri)
+ {
+       if (dry_run)
+               return SZ_DMAWFP;
+       buf[0] = CMD_DMAWFP;
+       if (cond == SINGLE)
+               buf[0] |= (0 << 1) | (0 << 0);
+       else if (cond == BURST)
+               buf[0] |= (1 << 1) | (0 << 0);
+       else
+               buf[0] |= (0 << 1) | (1 << 0);
+       peri &= 0x1f;
+       peri <<= 3;
+       buf[1] = peri;
+       PL330_DBGCMD_DUMP(SZ_DMAWFP, "\tDMAWFP%c %u\n",
+               cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'P'), peri >> 3);
+       return SZ_DMAWFP;
+ }
+ static inline u32 _emit_WMB(unsigned dry_run, u8 buf[])
+ {
+       if (dry_run)
+               return SZ_DMAWMB;
+       buf[0] = CMD_DMAWMB;
+       PL330_DBGCMD_DUMP(SZ_DMAWMB, "\tDMAWMB\n");
+       return SZ_DMAWMB;
+ }
+ struct _arg_GO {
+       u8 chan;
+       u32 addr;
+       unsigned ns;
+ };
+ static inline u32 _emit_GO(unsigned dry_run, u8 buf[],
+               const struct _arg_GO *arg)
+ {
+       u8 chan = arg->chan;
+       u32 addr = arg->addr;
+       unsigned ns = arg->ns;
+       if (dry_run)
+               return SZ_DMAGO;
+       buf[0] = CMD_DMAGO;
+       buf[0] |= (ns << 1);
+       buf[1] = chan & 0x7;
+       *((u32 *)&buf[2]) = addr;
+       return SZ_DMAGO;
+ }
+ #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
+ /* Returns Time-Out */
+ static bool _until_dmac_idle(struct pl330_thread *thrd)
+ {
+       void __iomem *regs = thrd->dmac->pinfo->base;
+       unsigned long loops = msecs_to_loops(5);
+       do {
+               /* Until Manager is Idle */
+               if (!(readl(regs + DBGSTATUS) & DBG_BUSY))
+                       break;
+               cpu_relax();
+       } while (--loops);
+       if (!loops)
+               return true;
+       return false;
+ }
+ static inline void _execute_DBGINSN(struct pl330_thread *thrd,
+               u8 insn[], bool as_manager)
+ {
+       void __iomem *regs = thrd->dmac->pinfo->base;
+       u32 val;
+       val = (insn[0] << 16) | (insn[1] << 24);
+       if (!as_manager) {
+               val |= (1 << 0);
+               val |= (thrd->id << 8); /* Channel Number */
+       }
+       writel(val, regs + DBGINST0);
+       val = *((u32 *)&insn[2]);
+       writel(val, regs + DBGINST1);
+       /* If timed out due to halted state-machine */
+       if (_until_dmac_idle(thrd)) {
+               dev_err(thrd->dmac->pinfo->dev, "DMAC halted!\n");
+               return;
+       }
+       /* Get going */
+       writel(0, regs + DBGCMD);
+ }
+ /*
+  * Mark a _pl330_req as free.
+  * We do it by writing DMAEND as the first instruction
+  * because no valid request is going to have DMAEND as
+  * its first instruction to execute.
+  */
+ static void mark_free(struct pl330_thread *thrd, int idx)
+ {
+       struct _pl330_req *req = &thrd->req[idx];
+       _emit_END(0, req->mc_cpu);
+       req->mc_len = 0;
+       thrd->req_running = -1;
+ }
+ static inline u32 _state(struct pl330_thread *thrd)
+ {
+       void __iomem *regs = thrd->dmac->pinfo->base;
+       u32 val;
+       if (is_manager(thrd))
+               val = readl(regs + DS) & 0xf;
+       else
+               val = readl(regs + CS(thrd->id)) & 0xf;
+       switch (val) {
+       case DS_ST_STOP:
+               return PL330_STATE_STOPPED;
+       case DS_ST_EXEC:
+               return PL330_STATE_EXECUTING;
+       case DS_ST_CMISS:
+               return PL330_STATE_CACHEMISS;
+       case DS_ST_UPDTPC:
+               return PL330_STATE_UPDTPC;
+       case DS_ST_WFE:
+               return PL330_STATE_WFE;
+       case DS_ST_FAULT:
+               return PL330_STATE_FAULTING;
+       case DS_ST_ATBRR:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_ATBARRIER;
+       case DS_ST_QBUSY:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_QUEUEBUSY;
+       case DS_ST_WFP:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_WFP;
+       case DS_ST_KILL:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_KILLING;
+       case DS_ST_CMPLT:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_COMPLETING;
+       case DS_ST_FLTCMP:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_FAULT_COMPLETING;
+       default:
+               return PL330_STATE_INVALID;
+       }
+ }
+ static void _stop(struct pl330_thread *thrd)
+ {
+       void __iomem *regs = thrd->dmac->pinfo->base;
+       u8 insn[6] = {0, 0, 0, 0, 0, 0};
+       if (_state(thrd) == PL330_STATE_FAULT_COMPLETING)
+               UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING);
+       /* Return if nothing needs to be done */
+       if (_state(thrd) == PL330_STATE_COMPLETING
+                 || _state(thrd) == PL330_STATE_KILLING
+                 || _state(thrd) == PL330_STATE_STOPPED)
+               return;
+       _emit_KILL(0, insn);
+       /* Stop generating interrupts for SEV */
+       writel(readl(regs + INTEN) & ~(1 << thrd->ev), regs + INTEN);
+       _execute_DBGINSN(thrd, insn, is_manager(thrd));
+ }
+ /* Start doing req 'idx' of thread 'thrd' */
+ static bool _trigger(struct pl330_thread *thrd)
+ {
+       void __iomem *regs = thrd->dmac->pinfo->base;
+       struct _pl330_req *req;
+       struct pl330_req *r;
+       struct _arg_GO go;
+       unsigned ns;
+       u8 insn[6] = {0, 0, 0, 0, 0, 0};
+       int idx;
+       /* Return if already ACTIVE */
+       if (_state(thrd) != PL330_STATE_STOPPED)
+               return true;
+       idx = 1 - thrd->lstenq;
+       if (!IS_FREE(&thrd->req[idx]))
+               req = &thrd->req[idx];
+       else {
+               idx = thrd->lstenq;
+               if (!IS_FREE(&thrd->req[idx]))
+                       req = &thrd->req[idx];
+               else
+                       req = NULL;
+       }
+       /* Return if no request */
+       if (!req || !req->r)
+               return true;
+       r = req->r;
+       if (r->cfg)
+               ns = r->cfg->nonsecure ? 1 : 0;
+       else if (readl(regs + CS(thrd->id)) & CS_CNS)
+               ns = 1;
+       else
+               ns = 0;
+       /* See 'Abort Sources' point-4 at Page 2-25 */
+       if (_manager_ns(thrd) && !ns)
+               dev_info(thrd->dmac->pinfo->dev, "%s:%d Recipe for ABORT!\n",
+                       __func__, __LINE__);
+       go.chan = thrd->id;
+       go.addr = req->mc_bus;
+       go.ns = ns;
+       _emit_GO(0, insn, &go);
+       /* Set to generate interrupts for SEV */
+       writel(readl(regs + INTEN) | (1 << thrd->ev), regs + INTEN);
+       /* Only manager can execute GO */
+       _execute_DBGINSN(thrd, insn, true);
+       thrd->req_running = idx;
+       return true;
+ }
+ static bool _start(struct pl330_thread *thrd)
+ {
+       switch (_state(thrd)) {
+       case PL330_STATE_FAULT_COMPLETING:
+               UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING);
+               if (_state(thrd) == PL330_STATE_KILLING)
+                       UNTIL(thrd, PL330_STATE_STOPPED)
+       case PL330_STATE_FAULTING:
+               _stop(thrd);
+       case PL330_STATE_KILLING:
+       case PL330_STATE_COMPLETING:
+               UNTIL(thrd, PL330_STATE_STOPPED)
+       case PL330_STATE_STOPPED:
+               return _trigger(thrd);
+       case PL330_STATE_WFP:
+       case PL330_STATE_QUEUEBUSY:
+       case PL330_STATE_ATBARRIER:
+       case PL330_STATE_UPDTPC:
+       case PL330_STATE_CACHEMISS:
+       case PL330_STATE_EXECUTING:
+               return true;
+       case PL330_STATE_WFE: /* For RESUME, nothing yet */
+       default:
+               return false;
+       }
+ }
+ static inline int _ldst_memtomem(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs, int cyc)
+ {
+       int off = 0;
+       struct pl330_config *pcfg = pxs->r->cfg->pcfg;
+       /* check lock-up free version */
+       if (get_revision(pcfg->periph_id) >= PERIPH_REV_R1P0) {
+               while (cyc--) {
+                       off += _emit_LD(dry_run, &buf[off], ALWAYS);
+                       off += _emit_ST(dry_run, &buf[off], ALWAYS);
+               }
+       } else {
+               while (cyc--) {
+                       off += _emit_LD(dry_run, &buf[off], ALWAYS);
+                       off += _emit_RMB(dry_run, &buf[off]);
+                       off += _emit_ST(dry_run, &buf[off], ALWAYS);
+                       off += _emit_WMB(dry_run, &buf[off]);
+               }
+       }
+       return off;
+ }
+ static inline int _ldst_devtomem(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs, int cyc)
+ {
+       int off = 0;
+       while (cyc--) {
+               off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->r->peri);
+               off += _emit_LDP(dry_run, &buf[off], SINGLE, pxs->r->peri);
+               off += _emit_ST(dry_run, &buf[off], ALWAYS);
+               off += _emit_FLUSHP(dry_run, &buf[off], pxs->r->peri);
+       }
+       return off;
+ }
+ static inline int _ldst_memtodev(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs, int cyc)
+ {
+       int off = 0;
+       while (cyc--) {
+               off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->r->peri);
+               off += _emit_LD(dry_run, &buf[off], ALWAYS);
+               off += _emit_STP(dry_run, &buf[off], SINGLE, pxs->r->peri);
+               off += _emit_FLUSHP(dry_run, &buf[off], pxs->r->peri);
+       }
+       return off;
+ }
+ static int _bursts(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs, int cyc)
+ {
+       int off = 0;
+       switch (pxs->r->rqtype) {
+       case MEMTODEV:
+               off += _ldst_memtodev(dry_run, &buf[off], pxs, cyc);
+               break;
+       case DEVTOMEM:
+               off += _ldst_devtomem(dry_run, &buf[off], pxs, cyc);
+               break;
+       case MEMTOMEM:
+               off += _ldst_memtomem(dry_run, &buf[off], pxs, cyc);
+               break;
+       default:
+               off += 0x40000000; /* Scare off the Client */
+               break;
+       }
+       return off;
+ }
+ /* Returns bytes consumed and updates bursts */
+ static inline int _loop(unsigned dry_run, u8 buf[],
+               unsigned long *bursts, const struct _xfer_spec *pxs)
+ {
+       int cyc, cycmax, szlp, szlpend, szbrst, off;
+       unsigned lcnt0, lcnt1, ljmp0, ljmp1;
+       struct _arg_LPEND lpend;
+       /* Max iterations possible in DMALP is 256 */
+       if (*bursts >= 256*256) {
+               lcnt1 = 256;
+               lcnt0 = 256;
+               cyc = *bursts / lcnt1 / lcnt0;
+       } else if (*bursts > 256) {
+               lcnt1 = 256;
+               lcnt0 = *bursts / lcnt1;
+               cyc = 1;
+       } else {
+               lcnt1 = *bursts;
+               lcnt0 = 0;
+               cyc = 1;
+       }
+       szlp = _emit_LP(1, buf, 0, 0);
+       szbrst = _bursts(1, buf, pxs, 1);
+       lpend.cond = ALWAYS;
+       lpend.forever = false;
+       lpend.loop = 0;
+       lpend.bjump = 0;
+       szlpend = _emit_LPEND(1, buf, &lpend);
+       if (lcnt0) {
+               szlp *= 2;
+               szlpend *= 2;
+       }
+       /*
+        * Max bursts that we can unroll due to limit on the
+        * size of backward jump that can be encoded in DMALPEND
+        * which is 8-bits and hence 255
+        */
+       cycmax = (255 - (szlp + szlpend)) / szbrst;
+       cyc = (cycmax < cyc) ? cycmax : cyc;
+       off = 0;
+       if (lcnt0) {
+               off += _emit_LP(dry_run, &buf[off], 0, lcnt0);
+               ljmp0 = off;
+       }
+       off += _emit_LP(dry_run, &buf[off], 1, lcnt1);
+       ljmp1 = off;
+       off += _bursts(dry_run, &buf[off], pxs, cyc);
+       lpend.cond = ALWAYS;
+       lpend.forever = false;
+       lpend.loop = 1;
+       lpend.bjump = off - ljmp1;
+       off += _emit_LPEND(dry_run, &buf[off], &lpend);
+       if (lcnt0) {
+               lpend.cond = ALWAYS;
+               lpend.forever = false;
+               lpend.loop = 0;
+               lpend.bjump = off - ljmp0;
+               off += _emit_LPEND(dry_run, &buf[off], &lpend);
+       }
+       *bursts = lcnt1 * cyc;
+       if (lcnt0)
+               *bursts *= lcnt0;
+       return off;
+ }
+ static inline int _setup_loops(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs)
+ {
+       struct pl330_xfer *x = pxs->x;
+       u32 ccr = pxs->ccr;
+       unsigned long c, bursts = BYTE_TO_BURST(x->bytes, ccr);
+       int off = 0;
+       while (bursts) {
+               c = bursts;
+               off += _loop(dry_run, &buf[off], &c, pxs);
+               bursts -= c;
+       }
+       return off;
+ }
+ static inline int _setup_xfer(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs)
+ {
+       struct pl330_xfer *x = pxs->x;
+       int off = 0;
+       /* DMAMOV SAR, x->src_addr */
+       off += _emit_MOV(dry_run, &buf[off], SAR, x->src_addr);
+       /* DMAMOV DAR, x->dst_addr */
+       off += _emit_MOV(dry_run, &buf[off], DAR, x->dst_addr);
+       /* Setup Loop(s) */
+       off += _setup_loops(dry_run, &buf[off], pxs);
+       return off;
+ }
+ /*
+  * A req is a sequence of one or more xfer units.
+  * Returns the number of bytes taken to setup the MC for the req.
+  */
+ static int _setup_req(unsigned dry_run, struct pl330_thread *thrd,
+               unsigned index, struct _xfer_spec *pxs)
+ {
+       struct _pl330_req *req = &thrd->req[index];
+       struct pl330_xfer *x;
+       u8 *buf = req->mc_cpu;
+       int off = 0;
+       PL330_DBGMC_START(req->mc_bus);
+       /* DMAMOV CCR, ccr */
+       off += _emit_MOV(dry_run, &buf[off], CCR, pxs->ccr);
+       x = pxs->r->x;
+       do {
+               /* Error if xfer length is not aligned at burst size */
+               if (x->bytes % (BRST_SIZE(pxs->ccr) * BRST_LEN(pxs->ccr)))
+                       return -EINVAL;
+               pxs->x = x;
+               off += _setup_xfer(dry_run, &buf[off], pxs);
+               x = x->next;
+       } while (x);
+       /* DMASEV peripheral/event */
+       off += _emit_SEV(dry_run, &buf[off], thrd->ev);
+       /* DMAEND */
+       off += _emit_END(dry_run, &buf[off]);
+       return off;
+ }
+ static inline u32 _prepare_ccr(const struct pl330_reqcfg *rqc)
+ {
+       u32 ccr = 0;
+       if (rqc->src_inc)
+               ccr |= CC_SRCINC;
+       if (rqc->dst_inc)
+               ccr |= CC_DSTINC;
+       /* We set same protection levels for Src and DST for now */
+       if (rqc->privileged)
+               ccr |= CC_SRCPRI | CC_DSTPRI;
+       if (rqc->nonsecure)
+               ccr |= CC_SRCNS | CC_DSTNS;
+       if (rqc->insnaccess)
+               ccr |= CC_SRCIA | CC_DSTIA;
+       ccr |= (((rqc->brst_len - 1) & 0xf) << CC_SRCBRSTLEN_SHFT);
+       ccr |= (((rqc->brst_len - 1) & 0xf) << CC_DSTBRSTLEN_SHFT);
+       ccr |= (rqc->brst_size << CC_SRCBRSTSIZE_SHFT);
+       ccr |= (rqc->brst_size << CC_DSTBRSTSIZE_SHFT);
+       ccr |= (rqc->scctl << CC_SRCCCTRL_SHFT);
+       ccr |= (rqc->dcctl << CC_DSTCCTRL_SHFT);
+       ccr |= (rqc->swap << CC_SWAP_SHFT);
+       return ccr;
+ }
+ static inline bool _is_valid(u32 ccr)
+ {
+       enum pl330_dstcachectrl dcctl;
+       enum pl330_srccachectrl scctl;
+       dcctl = (ccr >> CC_DSTCCTRL_SHFT) & CC_DRCCCTRL_MASK;
+       scctl = (ccr >> CC_SRCCCTRL_SHFT) & CC_SRCCCTRL_MASK;
+       if (dcctl == DINVALID1 || dcctl == DINVALID2
+                       || scctl == SINVALID1 || scctl == SINVALID2)
+               return false;
+       else
+               return true;
+ }
+ /*
+  * Submit a list of xfers after which the client wants notification.
+  * Client is not notified after each xfer unit, just once after all
+  * xfer units are done or some error occurs.
+  */
+ static int pl330_submit_req(void *ch_id, struct pl330_req *r)
+ {
+       struct pl330_thread *thrd = ch_id;
+       struct pl330_dmac *pl330;
+       struct pl330_info *pi;
+       struct _xfer_spec xs;
+       unsigned long flags;
+       void __iomem *regs;
+       unsigned idx;
+       u32 ccr;
+       int ret = 0;
+       /* No Req or Unacquired Channel or DMAC */
+       if (!r || !thrd || thrd->free)
+               return -EINVAL;
+       pl330 = thrd->dmac;
+       pi = pl330->pinfo;
+       regs = pi->base;
+       if (pl330->state == DYING
+               || pl330->dmac_tbd.reset_chan & (1 << thrd->id)) {
+               dev_info(thrd->dmac->pinfo->dev, "%s:%d\n",
+                       __func__, __LINE__);
+               return -EAGAIN;
+       }
+       /* If request for non-existing peripheral */
+       if (r->rqtype != MEMTOMEM && r->peri >= pi->pcfg.num_peri) {
+               dev_info(thrd->dmac->pinfo->dev,
+                               "%s:%d Invalid peripheral(%u)!\n",
+                               __func__, __LINE__, r->peri);
+               return -EINVAL;
+       }
+       spin_lock_irqsave(&pl330->lock, flags);
+       if (_queue_full(thrd)) {
+               ret = -EAGAIN;
+               goto xfer_exit;
+       }
+       /* Prefer Secure Channel */
+       if (!_manager_ns(thrd))
+               r->cfg->nonsecure = 0;
+       else
+               r->cfg->nonsecure = 1;
+       /* Use last settings, if not provided */
+       if (r->cfg)
+               ccr = _prepare_ccr(r->cfg);
+       else
+               ccr = readl(regs + CC(thrd->id));
+       /* If this req doesn't have valid xfer settings */
+       if (!_is_valid(ccr)) {
+               ret = -EINVAL;
+               dev_info(thrd->dmac->pinfo->dev, "%s:%d Invalid CCR(%x)!\n",
+                       __func__, __LINE__, ccr);
+               goto xfer_exit;
+       }
+       idx = IS_FREE(&thrd->req[0]) ? 0 : 1;
+       xs.ccr = ccr;
+       xs.r = r;
+       /* First dry run to check if req is acceptable */
+       ret = _setup_req(1, thrd, idx, &xs);
+       if (ret < 0)
+               goto xfer_exit;
+       if (ret > pi->mcbufsz / 2) {
+               dev_info(thrd->dmac->pinfo->dev,
+                       "%s:%d Trying increasing mcbufsz\n",
+                               __func__, __LINE__);
+               ret = -ENOMEM;
+               goto xfer_exit;
+       }
+       /* Hook the request */
+       thrd->lstenq = idx;
+       thrd->req[idx].mc_len = _setup_req(0, thrd, idx, &xs);
+       thrd->req[idx].r = r;
+       ret = 0;
+ xfer_exit:
+       spin_unlock_irqrestore(&pl330->lock, flags);
+       return ret;
+ }
+ static void pl330_dotask(unsigned long data)
+ {
+       struct pl330_dmac *pl330 = (struct pl330_dmac *) data;
+       struct pl330_info *pi = pl330->pinfo;
+       unsigned long flags;
+       int i;
+       spin_lock_irqsave(&pl330->lock, flags);
+       /* The DMAC itself gone nuts */
+       if (pl330->dmac_tbd.reset_dmac) {
+               pl330->state = DYING;
+               /* Reset the manager too */
+               pl330->dmac_tbd.reset_mngr = true;
+               /* Clear the reset flag */
+               pl330->dmac_tbd.reset_dmac = false;
+       }
+       if (pl330->dmac_tbd.reset_mngr) {
+               _stop(pl330->manager);
+               /* Reset all channels */
+               pl330->dmac_tbd.reset_chan = (1 << pi->pcfg.num_chan) - 1;
+               /* Clear the reset flag */
+               pl330->dmac_tbd.reset_mngr = false;
+       }
+       for (i = 0; i < pi->pcfg.num_chan; i++) {
+               if (pl330->dmac_tbd.reset_chan & (1 << i)) {
+                       struct pl330_thread *thrd = &pl330->channels[i];
+                       void __iomem *regs = pi->base;
+                       enum pl330_op_err err;
+                       _stop(thrd);
+                       if (readl(regs + FSC) & (1 << thrd->id))
+                               err = PL330_ERR_FAIL;
+                       else
+                               err = PL330_ERR_ABORT;
+                       spin_unlock_irqrestore(&pl330->lock, flags);
+                       _callback(thrd->req[1 - thrd->lstenq].r, err);
+                       _callback(thrd->req[thrd->lstenq].r, err);
+                       spin_lock_irqsave(&pl330->lock, flags);
+                       thrd->req[0].r = NULL;
+                       thrd->req[1].r = NULL;
+                       mark_free(thrd, 0);
+                       mark_free(thrd, 1);
+                       /* Clear the reset flag */
+                       pl330->dmac_tbd.reset_chan &= ~(1 << i);
+               }
+       }
+       spin_unlock_irqrestore(&pl330->lock, flags);
+       return;
+ }
+ /* Returns 1 if state was updated, 0 otherwise */
+ static int pl330_update(const struct pl330_info *pi)
+ {
+       struct _pl330_req *rqdone;
+       struct pl330_dmac *pl330;
+       unsigned long flags;
+       void __iomem *regs;
+       u32 val;
+       int id, ev, ret = 0;
+       if (!pi || !pi->pl330_data)
+               return 0;
+       regs = pi->base;
+       pl330 = pi->pl330_data;
+       spin_lock_irqsave(&pl330->lock, flags);
+       val = readl(regs + FSM) & 0x1;
+       if (val)
+               pl330->dmac_tbd.reset_mngr = true;
+       else
+               pl330->dmac_tbd.reset_mngr = false;
+       val = readl(regs + FSC) & ((1 << pi->pcfg.num_chan) - 1);
+       pl330->dmac_tbd.reset_chan |= val;
+       if (val) {
+               int i = 0;
+               while (i < pi->pcfg.num_chan) {
+                       if (val & (1 << i)) {
+                               dev_info(pi->dev,
+                                       "Reset Channel-%d\t CS-%x FTC-%x\n",
+                                               i, readl(regs + CS(i)),
+                                               readl(regs + FTC(i)));
+                               _stop(&pl330->channels[i]);
+                       }
+                       i++;
+               }
+       }
+       /* Check which event happened i.e, thread notified */
+       val = readl(regs + ES);
+       if (pi->pcfg.num_events < 32
+                       && val & ~((1 << pi->pcfg.num_events) - 1)) {
+               pl330->dmac_tbd.reset_dmac = true;
+               dev_err(pi->dev, "%s:%d Unexpected!\n", __func__, __LINE__);
+               ret = 1;
+               goto updt_exit;
+       }
+       for (ev = 0; ev < pi->pcfg.num_events; ev++) {
+               if (val & (1 << ev)) { /* Event occurred */
+                       struct pl330_thread *thrd;
+                       u32 inten = readl(regs + INTEN);
+                       int active;
+                       /* Clear the event */
+                       if (inten & (1 << ev))
+                               writel(1 << ev, regs + INTCLR);
+                       ret = 1;
+                       id = pl330->events[ev];
+                       thrd = &pl330->channels[id];
+                       active = thrd->req_running;
+                       if (active == -1) /* Aborted */
+                               continue;
+                       rqdone = &thrd->req[active];
+                       mark_free(thrd, active);
+                       /* Get going again ASAP */
+                       _start(thrd);
+                       /* For now, just make a list of callbacks to be done */
+                       list_add_tail(&rqdone->rqd, &pl330->req_done);
+               }
+       }
+       /* Now that we are in no hurry, do the callbacks */
+       while (!list_empty(&pl330->req_done)) {
+               struct pl330_req *r;
+               rqdone = container_of(pl330->req_done.next,
+                                       struct _pl330_req, rqd);
+               list_del_init(&rqdone->rqd);
+               /* Detach the req */
+               r = rqdone->r;
+               rqdone->r = NULL;
+               spin_unlock_irqrestore(&pl330->lock, flags);
+               _callback(r, PL330_ERR_NONE);
+               spin_lock_irqsave(&pl330->lock, flags);
+       }
+ updt_exit:
+       spin_unlock_irqrestore(&pl330->lock, flags);
+       if (pl330->dmac_tbd.reset_dmac
+                       || pl330->dmac_tbd.reset_mngr
+                       || pl330->dmac_tbd.reset_chan) {
+               ret = 1;
+               tasklet_schedule(&pl330->tasks);
+       }
+       return ret;
+ }
+ static int pl330_chan_ctrl(void *ch_id, enum pl330_chan_op op)
+ {
+       struct pl330_thread *thrd = ch_id;
+       struct pl330_dmac *pl330;
+       unsigned long flags;
 -      int ret = 0, active = thrd->req_running;
++      int ret = 0, active;
+       if (!thrd || thrd->free || thrd->dmac->state == DYING)
+               return -EINVAL;
+       pl330 = thrd->dmac;
++      active = thrd->req_running;
+       spin_lock_irqsave(&pl330->lock, flags);
+       switch (op) {
+       case PL330_OP_FLUSH:
+               /* Make sure the channel is stopped */
+               _stop(thrd);
+               thrd->req[0].r = NULL;
+               thrd->req[1].r = NULL;
+               mark_free(thrd, 0);
+               mark_free(thrd, 1);
+               break;
+       case PL330_OP_ABORT:
+               /* Make sure the channel is stopped */
+               _stop(thrd);
+               /* ABORT is only for the active req */
+               if (active == -1)
+                       break;
+               thrd->req[active].r = NULL;
+               mark_free(thrd, active);
+               /* Start the next */
+       case PL330_OP_START:
+               if ((active == -1) && !_start(thrd))
+                       ret = -EIO;
+               break;
+       default:
+               ret = -EINVAL;
+       }
+       spin_unlock_irqrestore(&pl330->lock, flags);
+       return ret;
+ }
+ /* Reserve an event */
+ static inline int _alloc_event(struct pl330_thread *thrd)
+ {
+       struct pl330_dmac *pl330 = thrd->dmac;
+       struct pl330_info *pi = pl330->pinfo;
+       int ev;
+       for (ev = 0; ev < pi->pcfg.num_events; ev++)
+               if (pl330->events[ev] == -1) {
+                       pl330->events[ev] = thrd->id;
+                       return ev;
+               }
+       return -1;
+ }
+ static bool _chan_ns(const struct pl330_info *pi, int i)
+ {
+       return pi->pcfg.irq_ns & (1 << i);
+ }
+ /* Upon success, returns IdentityToken for the
+  * allocated channel, NULL otherwise.
+  */
+ static void *pl330_request_channel(const struct pl330_info *pi)
+ {
+       struct pl330_thread *thrd = NULL;
+       struct pl330_dmac *pl330;
+       unsigned long flags;
+       int chans, i;
+       if (!pi || !pi->pl330_data)
+               return NULL;
  
- #define NR_DEFAULT_DESC       16
+       pl330 = pi->pl330_data;
+       if (pl330->state == DYING)
+               return NULL;
+       chans = pi->pcfg.num_chan;
+       spin_lock_irqsave(&pl330->lock, flags);
+       for (i = 0; i < chans; i++) {
+               thrd = &pl330->channels[i];
+               if ((thrd->free) && (!_manager_ns(thrd) ||
+                                       _chan_ns(pi, i))) {
+                       thrd->ev = _alloc_event(thrd);
+                       if (thrd->ev >= 0) {
+                               thrd->free = false;
+                               thrd->lstenq = 1;
+                               thrd->req[0].r = NULL;
+                               mark_free(thrd, 0);
+                               thrd->req[1].r = NULL;
+                               mark_free(thrd, 1);
+                               break;
+                       }
+               }
+               thrd = NULL;
+       }
+       spin_unlock_irqrestore(&pl330->lock, flags);
+       return thrd;
+ }
+ /* Release an event */
+ static inline void _free_event(struct pl330_thread *thrd, int ev)
+ {
+       struct pl330_dmac *pl330 = thrd->dmac;
+       struct pl330_info *pi = pl330->pinfo;
+       /* If the event is valid and was held by the thread */
+       if (ev >= 0 && ev < pi->pcfg.num_events
+                       && pl330->events[ev] == thrd->id)
+               pl330->events[ev] = -1;
+ }
+ static void pl330_release_channel(void *ch_id)
+ {
+       struct pl330_thread *thrd = ch_id;
+       struct pl330_dmac *pl330;
+       unsigned long flags;
+       if (!thrd || thrd->free)
+               return;
+       _stop(thrd);
+       _callback(thrd->req[1 - thrd->lstenq].r, PL330_ERR_ABORT);
+       _callback(thrd->req[thrd->lstenq].r, PL330_ERR_ABORT);
+       pl330 = thrd->dmac;
+       spin_lock_irqsave(&pl330->lock, flags);
+       _free_event(thrd, thrd->ev);
+       thrd->free = true;
+       spin_unlock_irqrestore(&pl330->lock, flags);
+ }
+ /* Initialize the structure for PL330 configuration, that can be used
+  * by the client driver the make best use of the DMAC
+  */
+ static void read_dmac_config(struct pl330_info *pi)
+ {
+       void __iomem *regs = pi->base;
+       u32 val;
+       val = readl(regs + CRD) >> CRD_DATA_WIDTH_SHIFT;
+       val &= CRD_DATA_WIDTH_MASK;
+       pi->pcfg.data_bus_width = 8 * (1 << val);
+       val = readl(regs + CRD) >> CRD_DATA_BUFF_SHIFT;
+       val &= CRD_DATA_BUFF_MASK;
+       pi->pcfg.data_buf_dep = val + 1;
+       val = readl(regs + CR0) >> CR0_NUM_CHANS_SHIFT;
+       val &= CR0_NUM_CHANS_MASK;
+       val += 1;
+       pi->pcfg.num_chan = val;
+       val = readl(regs + CR0);
+       if (val & CR0_PERIPH_REQ_SET) {
+               val = (val >> CR0_NUM_PERIPH_SHIFT) & CR0_NUM_PERIPH_MASK;
+               val += 1;
+               pi->pcfg.num_peri = val;
+               pi->pcfg.peri_ns = readl(regs + CR4);
+       } else {
+               pi->pcfg.num_peri = 0;
+       }
+       val = readl(regs + CR0);
+       if (val & CR0_BOOT_MAN_NS)
+               pi->pcfg.mode |= DMAC_MODE_NS;
+       else
+               pi->pcfg.mode &= ~DMAC_MODE_NS;
+       val = readl(regs + CR0) >> CR0_NUM_EVENTS_SHIFT;
+       val &= CR0_NUM_EVENTS_MASK;
+       val += 1;
+       pi->pcfg.num_events = val;
+       pi->pcfg.irq_ns = readl(regs + CR3);
+       pi->pcfg.periph_id = get_id(pi, PERIPH_ID);
+       pi->pcfg.pcell_id = get_id(pi, PCELL_ID);
+ }
+ static inline void _reset_thread(struct pl330_thread *thrd)
+ {
+       struct pl330_dmac *pl330 = thrd->dmac;
+       struct pl330_info *pi = pl330->pinfo;
+       thrd->req[0].mc_cpu = pl330->mcode_cpu
+                               + (thrd->id * pi->mcbufsz);
+       thrd->req[0].mc_bus = pl330->mcode_bus
+                               + (thrd->id * pi->mcbufsz);
+       thrd->req[0].r = NULL;
+       mark_free(thrd, 0);
+       thrd->req[1].mc_cpu = thrd->req[0].mc_cpu
+                               + pi->mcbufsz / 2;
+       thrd->req[1].mc_bus = thrd->req[0].mc_bus
+                               + pi->mcbufsz / 2;
+       thrd->req[1].r = NULL;
+       mark_free(thrd, 1);
+ }
+ static int dmac_alloc_threads(struct pl330_dmac *pl330)
+ {
+       struct pl330_info *pi = pl330->pinfo;
+       int chans = pi->pcfg.num_chan;
+       struct pl330_thread *thrd;
+       int i;
+       /* Allocate 1 Manager and 'chans' Channel threads */
+       pl330->channels = kzalloc((1 + chans) * sizeof(*thrd),
+                                       GFP_KERNEL);
+       if (!pl330->channels)
+               return -ENOMEM;
+       /* Init Channel threads */
+       for (i = 0; i < chans; i++) {
+               thrd = &pl330->channels[i];
+               thrd->id = i;
+               thrd->dmac = pl330;
+               _reset_thread(thrd);
+               thrd->free = true;
+       }
+       /* MANAGER is indexed at the end */
+       thrd = &pl330->channels[chans];
+       thrd->id = chans;
+       thrd->dmac = pl330;
+       thrd->free = false;
+       pl330->manager = thrd;
+       return 0;
+ }
+ static int dmac_alloc_resources(struct pl330_dmac *pl330)
+ {
+       struct pl330_info *pi = pl330->pinfo;
+       int chans = pi->pcfg.num_chan;
+       int ret;
  
- enum desc_status {
-       /* In the DMAC pool */
-       FREE,
-       /*
-        * Allocted to some channel during prep_xxx
-        * Also may be sitting on the work_list.
-        */
-       PREP,
        /*
-        * Sitting on the work_list and already submitted
-        * to the PL330 core. Not more than two descriptors
-        * of a channel can be BUSY at any time.
+        * Alloc MicroCode buffer for 'chans' Channel threads.
+        * A channel's buffer offset is (Channel_Id * MCODE_BUFF_PERCHAN)
         */
-       BUSY,
+       pl330->mcode_cpu = dma_alloc_coherent(pi->dev,
+                               chans * pi->mcbufsz,
+                               &pl330->mcode_bus, GFP_KERNEL);
+       if (!pl330->mcode_cpu) {
+               dev_err(pi->dev, "%s:%d Can't allocate memory!\n",
+                       __func__, __LINE__);
+               return -ENOMEM;
+       }
+       ret = dmac_alloc_threads(pl330);
+       if (ret) {
+               dev_err(pi->dev, "%s:%d Can't to create channels for DMAC!\n",
+                       __func__, __LINE__);
+               dma_free_coherent(pi->dev,
+                               chans * pi->mcbufsz,
+                               pl330->mcode_cpu, pl330->mcode_bus);
+               return ret;
+       }
+       return 0;
+ }
+ static int pl330_add(struct pl330_info *pi)
+ {
+       struct pl330_dmac *pl330;
+       void __iomem *regs;
+       int i, ret;
+       if (!pi || !pi->dev)
+               return -EINVAL;
+       /* If already added */
+       if (pi->pl330_data)
+               return -EINVAL;
        /*
-        * Sitting on the channel work_list but xfer done
-        * by PL330 core
+        * If the SoC can perform reset on the DMAC, then do it
+        * before reading its configuration.
         */
-       DONE,
};
+       if (pi->dmac_reset)
              pi->dmac_reset(pi);
  
- struct dma_pl330_chan {
-       /* Schedule desc completion */
-       struct tasklet_struct task;
+       regs = pi->base;
  
-       /* DMA-Engine Channel */
-       struct dma_chan chan;
+       /* Check if we can handle this DMAC */
+       if ((get_id(pi, PERIPH_ID) & 0xfffff) != PERIPH_ID_VAL
+          || get_id(pi, PCELL_ID) != PCELL_ID_VAL) {
+               dev_err(pi->dev, "PERIPH_ID 0x%x, PCELL_ID 0x%x !\n",
+                       get_id(pi, PERIPH_ID), get_id(pi, PCELL_ID));
+               return -EINVAL;
+       }
  
-       /* Last completed cookie */
-       dma_cookie_t completed;
+       /* Read the configuration of the DMAC */
+       read_dmac_config(pi);
  
-       /* List of to be xfered descriptors */
-       struct list_head work_list;
+       if (pi->pcfg.num_events == 0) {
+               dev_err(pi->dev, "%s:%d Can't work without events!\n",
+                       __func__, __LINE__);
+               return -EINVAL;
+       }
  
-       /* Pointer to the DMAC that manages this channel,
-        * NULL if the channel is available to be acquired.
-        * As the parent, this DMAC also provides descriptors
-        * to the channel.
-        */
-       struct dma_pl330_dmac *dmac;
+       pl330 = kzalloc(sizeof(*pl330), GFP_KERNEL);
+       if (!pl330) {
+               dev_err(pi->dev, "%s:%d Can't allocate memory!\n",
+                       __func__, __LINE__);
+               return -ENOMEM;
+       }
  
-       /* To protect channel manipulation */
-       spinlock_t lock;
+       /* Assign the info structure and private data */
+       pl330->pinfo = pi;
+       pi->pl330_data = pl330;
  
-       /* Token of a hardware channel thread of PL330 DMAC
-        * NULL if the channel is available to be acquired.
-        */
-       void *pl330_chid;
+       spin_lock_init(&pl330->lock);
  
-       /* For D-to-M and M-to-D channels */
-       int burst_sz; /* the peripheral fifo width */
-       int burst_len; /* the number of burst */
-       dma_addr_t fifo_addr;
+       INIT_LIST_HEAD(&pl330->req_done);
  
-       /* for cyclic capability */
-       bool cyclic;
};
+       /* Use default MC buffer size if not provided */
+       if (!pi->mcbufsz)
              pi->mcbufsz = MCODE_BUFF_PER_REQ * 2;
  
- struct dma_pl330_dmac {
-       struct pl330_info pif;
+       /* Mark all events as free */
+       for (i = 0; i < pi->pcfg.num_events; i++)
+               pl330->events[i] = -1;
  
-       /* DMA-Engine Device */
-       struct dma_device ddma;
+       /* Allocate resources needed by the DMAC */
+       ret = dmac_alloc_resources(pl330);
+       if (ret) {
+               dev_err(pi->dev, "Unable to create channels for DMAC\n");
+               kfree(pl330);
+               return ret;
+       }
  
-       /* Pool of descriptors available for the DMAC's channels */
-       struct list_head desc_pool;
-       /* To protect desc_pool manipulation */
-       spinlock_t pool_lock;
+       tasklet_init(&pl330->tasks, pl330_dotask, (unsigned long) pl330);
  
-       /* Peripheral channels connected to this DMAC */
-       struct dma_pl330_chan *peripherals; /* keep at end */
+       pl330->state = INIT;
  
-       struct clk *clk;
- };
+       return 0;
+ }
  
- struct dma_pl330_desc {
-       /* To attach to a queue as child */
-       struct list_head node;
+ static int dmac_free_threads(struct pl330_dmac *pl330)
+ {
+       struct pl330_info *pi = pl330->pinfo;
+       int chans = pi->pcfg.num_chan;
+       struct pl330_thread *thrd;
+       int i;
  
-       /* Descriptor for the DMA Engine API */
-       struct dma_async_tx_descriptor txd;
+       /* Release Channel threads */
+       for (i = 0; i < chans; i++) {
+               thrd = &pl330->channels[i];
+               pl330_release_channel((void *)thrd);
+       }
  
-       /* Xfer for PL330 core */
-       struct pl330_xfer px;
+       /* Free memory */
+       kfree(pl330->channels);
  
-       struct pl330_reqcfg rqcfg;
-       struct pl330_req req;
+       return 0;
+ }
  
-       enum desc_status status;
+ static void dmac_free_resources(struct pl330_dmac *pl330)
+ {
+       struct pl330_info *pi = pl330->pinfo;
+       int chans = pi->pcfg.num_chan;
  
-       /* The channel which currently holds this desc */
-       struct dma_pl330_chan *pchan;
- };
+       dmac_free_threads(pl330);
+       dma_free_coherent(pi->dev, chans * pi->mcbufsz,
+                               pl330->mcode_cpu, pl330->mcode_bus);
+ }
+ static void pl330_del(struct pl330_info *pi)
+ {
+       struct pl330_dmac *pl330;
+       if (!pi || !pi->pl330_data)
+               return;
+       pl330 = pi->pl330_data;
+       pl330->state = UNINIT;
+       tasklet_kill(&pl330->tasks);
+       /* Free DMAC resources */
+       dmac_free_resources(pl330);
+       kfree(pl330);
+       pi->pl330_data = NULL;
+ }
  
  /* forward declaration */
  static struct amba_driver pl330_driver;
@@@ -234,7 -2319,7 +2320,7 @@@ static void pl330_tasklet(unsigned lon
        /* Pick up ripe tomatoes */
        list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
                if (desc->status == DONE) {
-                       pch->completed = desc->txd.cookie;
+                       dma_cookie_complete(&desc->txd);
                        list_move_tail(&desc->node, &list);
                }
  
@@@ -305,7 -2390,7 +2391,7 @@@ static int pl330_alloc_chan_resources(s
  
        spin_lock_irqsave(&pch->lock, flags);
  
-       pch->completed = chan->cookie = 1;
+       dma_cookie_init(chan);
        pch->cyclic = false;
  
        pch->pl330_chid = pl330_request_channel(&pdmac->pif);
@@@ -340,7 -2425,6 +2426,6 @@@ static int pl330_control(struct dma_cha
                /* Mark all desc done */
                list_for_each_entry_safe(desc, _dt, &pch->work_list , node) {
                        desc->status = DONE;
-                       pch->completed = desc->txd.cookie;
                        list_move_tail(&desc->node, &list);
                }
  
@@@ -396,18 -2480,7 +2481,7 @@@ static enum dma_statu
  pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie,
                 struct dma_tx_state *txstate)
  {
-       struct dma_pl330_chan *pch = to_pchan(chan);
-       dma_cookie_t last_done, last_used;
-       int ret;
-       last_done = pch->completed;
-       last_used = chan->cookie;
-       ret = dma_async_is_complete(cookie, last_done, last_used);
-       dma_set_tx_state(txstate, last_done, last_used, 0);
-       return ret;
+       return dma_cookie_status(chan, cookie, txstate);
  }
  
  static void pl330_issue_pending(struct dma_chan *chan)
@@@ -430,26 -2503,16 +2504,16 @@@ static dma_cookie_t pl330_tx_submit(str
        spin_lock_irqsave(&pch->lock, flags);
  
        /* Assign cookies to all nodes */
-       cookie = tx->chan->cookie;
        while (!list_empty(&last->node)) {
                desc = list_entry(last->node.next, struct dma_pl330_desc, node);
  
-               if (++cookie < 0)
-                       cookie = 1;
-               desc->txd.cookie = cookie;
+               dma_cookie_assign(&desc->txd);
  
                list_move_tail(&desc->node, &pch->work_list);
        }
  
-       if (++cookie < 0)
-               cookie = 1;
-       last->txd.cookie = cookie;
+       cookie = dma_cookie_assign(&last->txd);
        list_add_tail(&last->node, &pch->work_list);
-       tx->chan->cookie = cookie;
        spin_unlock_irqrestore(&pch->lock, flags);
  
        return cookie;
@@@ -553,6 -2616,7 +2617,7 @@@ static struct dma_pl330_desc *pl330_get
        async_tx_ack(&desc->txd);
  
        desc->req.peri = peri_id ? pch->chan.chan_id : 0;
+       desc->rqcfg.pcfg = &pch->dmac->pif.pcfg;
  
        dma_async_tx_descriptor_init(&desc->txd, &pch->chan);
  
@@@ -621,7 -2685,8 +2686,8 @@@ static inline int get_burst_len(struct 
  
  static struct dma_async_tx_descriptor *pl330_prep_dma_cyclic(
                struct dma_chan *chan, dma_addr_t dma_addr, size_t len,
-               size_t period_len, enum dma_transfer_direction direction)
+               size_t period_len, enum dma_transfer_direction direction,
+               void *context)
  {
        struct dma_pl330_desc *desc;
        struct dma_pl330_chan *pch = to_pchan(chan);
@@@ -711,7 -2776,7 +2777,7 @@@ pl330_prep_dma_memcpy(struct dma_chan *
  static struct dma_async_tx_descriptor *
  pl330_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
                unsigned int sg_len, enum dma_transfer_direction direction,
-               unsigned long flg)
+               unsigned long flg, void *context)
  {
        struct dma_pl330_desc *first, *desc = NULL;
        struct dma_pl330_chan *pch = to_pchan(chan);
@@@ -829,7 -2894,7 +2895,7 @@@ pl330_probe(struct amba_device *adev, c
        if (IS_ERR(pdmac->clk)) {
                dev_err(&adev->dev, "Cannot get operation clock.\n");
                ret = -EINVAL;
-               goto probe_err1;
+               goto probe_err2;
        }
  
        amba_set_drvdata(adev, pdmac);
        ret = request_irq(irq, pl330_irq_handler, 0,
                        dev_name(&adev->dev), pi);
        if (ret)
-               goto probe_err2;
+               goto probe_err3;
  
        ret = pl330_add(pi);
        if (ret)
-               goto probe_err3;
+               goto probe_err4;
  
        INIT_LIST_HEAD(&pdmac->desc_pool);
        spin_lock_init(&pdmac->pool_lock);
        ret = dma_async_device_register(pd);
        if (ret) {
                dev_err(&adev->dev, "unable to register DMAC\n");
-               goto probe_err4;
+               goto probe_err5;
        }
  
        dev_info(&adev->dev,
  
        return 0;
  
- probe_err4:
+ probe_err5:
        pl330_del(pi);
- probe_err3:
+ probe_err4:
        free_irq(irq, pi);
+ probe_err3:
+ #ifndef CONFIG_PM_RUNTIME
+       clk_disable(pdmac->clk);
+ #endif
+       clk_put(pdmac->clk);
  probe_err2:
        iounmap(pi->base);
  probe_err1:
@@@ -1035,7 -3105,18 +3106,7 @@@ static struct amba_driver pl330_driver 
        .remove = pl330_remove,
  };
  
 -static int __init pl330_init(void)
 -{
 -      return amba_driver_register(&pl330_driver);
 -}
 -module_init(pl330_init);
 -
 -static void __exit pl330_exit(void)
 -{
 -      amba_driver_unregister(&pl330_driver);
 -      return;
 -}
 -module_exit(pl330_exit);
 +module_amba_driver(pl330_driver);
  
  MODULE_AUTHOR("Jaswinder Singh <jassi.brar@samsung.com>");
  MODULE_DESCRIPTION("API Driver for PL330 DMAC");
index 390863e7efbde4bb4ba37e210a1e694438b12cdd,492854b09d89152aeb9c759e0a54b9f3be534590..9819dc09ce08d24f7bd2924fd35d786cc013b0ac
@@@ -24,6 -24,7 +24,7 @@@
  #include <linux/seq_file.h>
  #include <linux/slab.h>
  #include <linux/stat.h>
+ #include <linux/types.h>
  
  #include <linux/mmc/host.h>
  #include <linux/mmc/sdio.h>
@@@ -173,6 -174,7 +174,7 @@@ struct atmel_mci 
  
        struct atmel_mci_dma    dma;
        struct dma_chan         *data_chan;
+       struct dma_slave_config dma_conf;
  
        u32                     cmd_status;
        u32                     data_status;
@@@ -863,16 -865,17 +865,17 @@@ atmci_prepare_data_dma(struct atmel_mc
  
        if (data->flags & MMC_DATA_READ) {
                direction = DMA_FROM_DEVICE;
-               slave_dirn = DMA_DEV_TO_MEM;
+               host->dma_conf.direction = slave_dirn = DMA_DEV_TO_MEM;
        } else {
                direction = DMA_TO_DEVICE;
-               slave_dirn = DMA_MEM_TO_DEV;
+               host->dma_conf.direction = slave_dirn = DMA_MEM_TO_DEV;
        }
  
        sglen = dma_map_sg(chan->device->dev, data->sg,
                        data->sg_len, direction);
  
-       desc = chan->device->device_prep_slave_sg(chan,
+       dmaengine_slave_config(chan, &host->dma_conf);
+       desc = dmaengine_prep_slave_sg(chan,
                        data->sg, sglen, slave_dirn,
                        DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
        if (!desc)
@@@ -969,14 -972,11 +972,14 @@@ static void atmci_start_request(struct 
        host->data_status = 0;
  
        if (host->need_reset) {
 +              iflags = atmci_readl(host, ATMCI_IMR);
 +              iflags &= (ATMCI_SDIOIRQA | ATMCI_SDIOIRQB);
                atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
                atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
                atmci_writel(host, ATMCI_MR, host->mode_reg);
                if (host->caps.has_cfg_reg)
                        atmci_writel(host, ATMCI_CFG, host->cfg_reg);
 +              atmci_writel(host, ATMCI_IER, iflags);
                host->need_reset = false;
        }
        atmci_writel(host, ATMCI_SDCR, slot->sdc_reg);
@@@ -1948,22 -1948,18 +1951,18 @@@ static bool atmci_filter(struct dma_cha
        }
  }
  
 -static void atmci_configure_dma(struct atmel_mci *host)
 +static bool atmci_configure_dma(struct atmel_mci *host)
  {
        struct mci_platform_data        *pdata;
  
        if (host == NULL)
 -              return;
 +              return false;
  
        pdata = host->pdev->dev.platform_data;
  
        if (pdata && find_slave_dev(pdata->dma_slave)) {
                dma_cap_mask_t mask;
  
-               setup_dma_addr(pdata->dma_slave,
-                              host->mapbase + ATMCI_TDR,
-                              host->mapbase + ATMCI_RDR);
                /* Try to grab a DMA channel */
                dma_cap_zero(mask);
                dma_cap_set(DMA_SLAVE, mask);
                        dma_request_channel(mask, atmci_filter, pdata->dma_slave);
        }
        if (!host->dma.chan) {
 -              dev_notice(&host->pdev->dev, "DMA not available, using PIO\n");
 +              dev_warn(&host->pdev->dev, "no DMA channel available\n");
 +              return false;
        } else {
                dev_info(&host->pdev->dev,
 -                                      "Using %s for DMA transfers\n",
 +                                      "using %s for DMA transfers\n",
                                        dma_chan_name(host->dma.chan));
+               host->dma_conf.src_addr = host->mapbase + ATMCI_RDR;
+               host->dma_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+               host->dma_conf.src_maxburst = 1;
+               host->dma_conf.dst_addr = host->mapbase + ATMCI_TDR;
+               host->dma_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+               host->dma_conf.dst_maxburst = 1;
+               host->dma_conf.device_fc = false;
 +              return true;
        }
  }
  
@@@ -2088,7 -2090,8 +2095,7 @@@ static int __init atmci_probe(struct pl
  
        /* Get MCI capabilities and set operations according to it */
        atmci_get_cap(host);
 -      if (host->caps.has_dma) {
 -              dev_info(&pdev->dev, "using DMA\n");
 +      if (host->caps.has_dma && atmci_configure_dma(host)) {
                host->prepare_data = &atmci_prepare_data_dma;
                host->submit_data = &atmci_submit_data_dma;
                host->stop_transfer = &atmci_stop_transfer_dma;
                host->submit_data = &atmci_submit_data_pdc;
                host->stop_transfer = &atmci_stop_transfer_pdc;
        } else {
 -              dev_info(&pdev->dev, "no DMA, no PDC\n");
 +              dev_info(&pdev->dev, "using PIO\n");
                host->prepare_data = &atmci_prepare_data;
                host->submit_data = &atmci_submit_data;
                host->stop_transfer = &atmci_stop_transfer;
        }
  
 -      if (host->caps.has_dma)
 -              atmci_configure_dma(host);
 -
        platform_set_drvdata(pdev, host);
  
        /* We need at least one slot to succeed */
diff --combined drivers/mmc/host/mmci.c
index 983e244eca769fcbd4be56b90780ff7c0156b84f,c55f9663eb135ea14fcad9ccbf52fd64360173da..032b84791a16fecc10a7da9a9bae4f460cc9e1b9
@@@ -30,6 -30,7 +30,7 @@@
  #include <linux/dma-mapping.h>
  #include <linux/amba/mmci.h>
  #include <linux/pm_runtime.h>
+ #include <linux/types.h>
  
  #include <asm/div64.h>
  #include <asm/io.h>
@@@ -53,8 -54,6 +54,8 @@@ static unsigned int fmax = 515633
   * @sdio: variant supports SDIO
   * @st_clkdiv: true if using a ST-specific clock divider algorithm
   * @blksz_datactrl16: true if Block size is at b16..b30 position in datactrl register
 + * @pwrreg_powerup: power up value for MMCIPOWER register
 + * @signal_direction: input/out direction of bus signals can be indicated
   */
  struct variant_data {
        unsigned int            clkreg;
        bool                    sdio;
        bool                    st_clkdiv;
        bool                    blksz_datactrl16;
 +      u32                     pwrreg_powerup;
 +      bool                    signal_direction;
  };
  
  static struct variant_data variant_arm = {
        .fifosize               = 16 * 4,
        .fifohalfsize           = 8 * 4,
        .datalength_bits        = 16,
 +      .pwrreg_powerup         = MCI_PWR_UP,
  };
  
  static struct variant_data variant_arm_extended_fifo = {
        .fifosize               = 128 * 4,
        .fifohalfsize           = 64 * 4,
        .datalength_bits        = 16,
 +      .pwrreg_powerup         = MCI_PWR_UP,
  };
  
  static struct variant_data variant_u300 = {
@@@ -89,8 -84,6 +90,8 @@@
        .clkreg_enable          = MCI_ST_U300_HWFCEN,
        .datalength_bits        = 16,
        .sdio                   = true,
 +      .pwrreg_powerup         = MCI_PWR_ON,
 +      .signal_direction       = true,
  };
  
  static struct variant_data variant_ux500 = {
        .datalength_bits        = 24,
        .sdio                   = true,
        .st_clkdiv              = true,
 +      .pwrreg_powerup         = MCI_PWR_ON,
 +      .signal_direction       = true,
  };
  
  static struct variant_data variant_ux500v2 = {
        .sdio                   = true,
        .st_clkdiv              = true,
        .blksz_datactrl16       = true,
 +      .pwrreg_powerup         = MCI_PWR_ON,
 +      .signal_direction       = true,
  };
  
 +/*
 + * This must be called with host->lock held
 + */
 +static void mmci_write_clkreg(struct mmci_host *host, u32 clk)
 +{
 +      if (host->clk_reg != clk) {
 +              host->clk_reg = clk;
 +              writel(clk, host->base + MMCICLOCK);
 +      }
 +}
 +
 +/*
 + * This must be called with host->lock held
 + */
 +static void mmci_write_pwrreg(struct mmci_host *host, u32 pwr)
 +{
 +      if (host->pwr_reg != pwr) {
 +              host->pwr_reg = pwr;
 +              writel(pwr, host->base + MMCIPOWER);
 +      }
 +}
 +
  /*
   * This must be called with host->lock held
   */
@@@ -187,7 -154,7 +188,7 @@@ static void mmci_set_clkreg(struct mmci
        if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_8)
                clk |= MCI_ST_8BIT_BUS;
  
 -      writel(clk, host->base + MMCICLOCK);
 +      mmci_write_clkreg(host, clk);
  }
  
  static void
@@@ -200,10 -167,14 +201,10 @@@ mmci_request_end(struct mmci_host *host
        host->mrq = NULL;
        host->cmd = NULL;
  
 -      /*
 -       * Need to drop the host lock here; mmc_request_done may call
 -       * back into the driver...
 -       */
 -      spin_unlock(&host->lock);
 -      pm_runtime_put(mmc_dev(host->mmc));
        mmc_request_done(host->mmc, mrq);
 -      spin_lock(&host->lock);
 +
 +      pm_runtime_mark_last_busy(mmc_dev(host->mmc));
 +      pm_runtime_put_autosuspend(mmc_dev(host->mmc));
  }
  
  static void mmci_set_mask1(struct mmci_host *host, unsigned int mask)
@@@ -400,6 -371,7 +401,7 @@@ static int mmci_dma_prep_data(struct mm
                .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
                .src_maxburst = variant->fifohalfsize >> 2, /* # of words */
                .dst_maxburst = variant->fifohalfsize >> 2, /* # of words */
+               .device_fc = false,
        };
        struct dma_chan *chan;
        struct dma_device *device;
                return -EINVAL;
  
        dmaengine_slave_config(chan, &conf);
-       desc = device->device_prep_slave_sg(chan, data->sg, nr_sg,
+       desc = dmaengine_prep_slave_sg(chan, data->sg, nr_sg,
                                            conf.direction, DMA_CTRL_ACK);
        if (!desc)
                goto unmap_exit;
@@@ -637,11 -609,6 +639,11 @@@ static void mmci_start_data(struct mmci
        if (data->flags & MMC_DATA_READ)
                datactrl |= MCI_DPSM_DIRECTION;
  
 +      /* The ST Micro variants has a special bit to enable SDIO */
 +      if (variant->sdio && host->mmc->card)
 +              if (mmc_card_sdio(host->mmc->card))
 +                      datactrl |= MCI_ST_DPSM_SDIOEN;
 +
        /*
         * Attempt to use DMA operation mode, if this
         * should fail, fall back to PIO mode
                irqmask = MCI_TXFIFOHALFEMPTYMASK;
        }
  
 -      /* The ST Micro variants has a special bit to enable SDIO */
 -      if (variant->sdio && host->mmc->card)
 -              if (mmc_card_sdio(host->mmc->card))
 -                      datactrl |= MCI_ST_DPSM_SDIOEN;
 -
        writel(datactrl, base + MMCIDATACTRL);
        writel(readl(base + MMCIMASK0) & ~MCI_DATAENDMASK, base + MMCIMASK0);
        mmci_set_mask1(host, irqmask);
@@@ -816,24 -788,7 +818,24 @@@ static int mmci_pio_read(struct mmci_ho
                if (count <= 0)
                        break;
  
 -              readsl(base + MMCIFIFO, ptr, count >> 2);
 +              /*
 +               * SDIO especially may want to send something that is
 +               * not divisible by 4 (as opposed to card sectors
 +               * etc). Therefore make sure to always read the last bytes
 +               * while only doing full 32-bit reads towards the FIFO.
 +               */
 +              if (unlikely(count & 0x3)) {
 +                      if (count < 4) {
 +                              unsigned char buf[4];
 +                              readsl(base + MMCIFIFO, buf, 1);
 +                              memcpy(ptr, buf, count);
 +                      } else {
 +                              readsl(base + MMCIFIFO, ptr, count >> 2);
 +                              count &= ~0x3;
 +                      }
 +              } else {
 +                      readsl(base + MMCIFIFO, ptr, count >> 2);
 +              }
  
                ptr += count;
                remain -= count;
@@@ -868,13 -823,14 +870,13 @@@ static int mmci_pio_write(struct mmci_h
                 */
                if (variant->sdio &&
                    mmc_card_sdio(host->mmc->card)) {
 +                      u32 clk;
                        if (count < 8)
 -                              writel(readl(host->base + MMCICLOCK) &
 -                                      ~variant->clkreg_enable,
 -                                      host->base + MMCICLOCK);
 +                              clk = host->clk_reg & ~variant->clkreg_enable;
                        else
 -                              writel(readl(host->base + MMCICLOCK) |
 -                                      variant->clkreg_enable,
 -                                      host->base + MMCICLOCK);
 +                              clk = host->clk_reg | variant->clkreg_enable;
 +
 +                      mmci_write_clkreg(host, clk);
                }
  
                /*
@@@ -1061,17 -1017,10 +1063,17 @@@ static void mmci_request(struct mmc_hos
  static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  {
        struct mmci_host *host = mmc_priv(mmc);
 +      struct variant_data *variant = host->variant;
        u32 pwr = 0;
        unsigned long flags;
        int ret;
  
 +      pm_runtime_get_sync(mmc_dev(mmc));
 +
 +      if (host->plat->ios_handler &&
 +              host->plat->ios_handler(mmc_dev(mmc), ios))
 +                      dev_err(mmc_dev(mmc), "platform ios_handler failed\n");
 +
        switch (ios->power_mode) {
        case MMC_POWER_OFF:
                if (host->vcc)
                                 * power should be rare so we print an error
                                 * and return here.
                                 */
 -                              return;
 +                              goto out;
                        }
                }
 -              if (host->plat->vdd_handler)
 -                      pwr |= host->plat->vdd_handler(mmc_dev(mmc), ios->vdd,
 -                                                     ios->power_mode);
 -              /* The ST version does not have this, fall through to POWER_ON */
 -              if (host->hw_designer != AMBA_VENDOR_ST) {
 -                      pwr |= MCI_PWR_UP;
 -                      break;
 -              }
 +              /*
 +               * The ST Micro variant doesn't have the PL180s MCI_PWR_UP
 +               * and instead uses MCI_PWR_ON so apply whatever value is
 +               * configured in the variant data.
 +               */
 +              pwr |= variant->pwrreg_powerup;
 +
 +              break;
        case MMC_POWER_ON:
                pwr |= MCI_PWR_ON;
                break;
        }
  
 +      if (variant->signal_direction && ios->power_mode != MMC_POWER_OFF) {
 +              /*
 +               * The ST Micro variant has some additional bits
 +               * indicating signal direction for the signals in
 +               * the SD/MMC bus and feedback-clock usage.
 +               */
 +              pwr |= host->plat->sigdir;
 +
 +              if (ios->bus_width == MMC_BUS_WIDTH_4)
 +                      pwr &= ~MCI_ST_DATA74DIREN;
 +              else if (ios->bus_width == MMC_BUS_WIDTH_1)
 +                      pwr &= (~MCI_ST_DATA74DIREN &
 +                              ~MCI_ST_DATA31DIREN &
 +                              ~MCI_ST_DATA2DIREN);
 +      }
 +
        if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
                if (host->hw_designer != AMBA_VENDOR_ST)
                        pwr |= MCI_ROD;
        spin_lock_irqsave(&host->lock, flags);
  
        mmci_set_clkreg(host, ios->clock);
 -
 -      if (host->pwr != pwr) {
 -              host->pwr = pwr;
 -              writel(pwr, host->base + MMCIPOWER);
 -      }
 +      mmci_write_pwrreg(host, pwr);
  
        spin_unlock_irqrestore(&host->lock, flags);
 +
 + out:
 +      pm_runtime_mark_last_busy(mmc_dev(mmc));
 +      pm_runtime_put_autosuspend(mmc_dev(mmc));
  }
  
  static int mmci_get_ro(struct mmc_host *mmc)
@@@ -1340,13 -1273,12 +1342,13 @@@ static int __devinit mmci_probe(struct 
        /*
         * Block size can be up to 2048 bytes, but must be a power of two.
         */
 -      mmc->max_blk_size = 2048;
 +      mmc->max_blk_size = 1 << 11;
  
        /*
 -       * No limit on the number of blocks transferred.
 +       * Limit the number of blocks transferred so that we don't overflow
 +       * the maximum request size.
         */
 -      mmc->max_blk_count = mmc->max_req_size;
 +      mmc->max_blk_count = mmc->max_req_size >> 11;
  
        spin_lock_init(&host->lock);
  
        if (ret)
                goto unmap;
  
 -      if (dev->irq[1] == NO_IRQ)
 +      if (dev->irq[1] == NO_IRQ || !dev->irq[1])
                host->singleirq = true;
        else {
                ret = request_irq(dev->irq[1], mmci_pio_irq, IRQF_SHARED,
  
        mmci_dma_setup(host);
  
 +      pm_runtime_set_autosuspend_delay(&dev->dev, 50);
 +      pm_runtime_use_autosuspend(&dev->dev);
        pm_runtime_put(&dev->dev);
  
        mmc_add_host(mmc);
@@@ -1501,49 -1431,43 +1503,49 @@@ static int __devexit mmci_remove(struc
        return 0;
  }
  
 -#ifdef CONFIG_PM
 -static int mmci_suspend(struct amba_device *dev, pm_message_t state)
 +#ifdef CONFIG_SUSPEND
 +static int mmci_suspend(struct device *dev)
  {
 -      struct mmc_host *mmc = amba_get_drvdata(dev);
 +      struct amba_device *adev = to_amba_device(dev);
 +      struct mmc_host *mmc = amba_get_drvdata(adev);
        int ret = 0;
  
        if (mmc) {
                struct mmci_host *host = mmc_priv(mmc);
  
                ret = mmc_suspend_host(mmc);
 -              if (ret == 0)
 +              if (ret == 0) {
 +                      pm_runtime_get_sync(dev);
                        writel(0, host->base + MMCIMASK0);
 +              }
        }
  
        return ret;
  }
  
 -static int mmci_resume(struct amba_device *dev)
 +static int mmci_resume(struct device *dev)
  {
 -      struct mmc_host *mmc = amba_get_drvdata(dev);
 +      struct amba_device *adev = to_amba_device(dev);
 +      struct mmc_host *mmc = amba_get_drvdata(adev);
        int ret = 0;
  
        if (mmc) {
                struct mmci_host *host = mmc_priv(mmc);
  
                writel(MCI_IRQENABLE, host->base + MMCIMASK0);
 +              pm_runtime_put(dev);
  
                ret = mmc_resume_host(mmc);
        }
  
        return ret;
  }
 -#else
 -#define mmci_suspend  NULL
 -#define mmci_resume   NULL
  #endif
  
 +static const struct dev_pm_ops mmci_dev_pm_ops = {
 +      SET_SYSTEM_SLEEP_PM_OPS(mmci_suspend, mmci_resume)
 +};
 +
  static struct amba_id mmci_ids[] = {
        {
                .id     = 0x00041180,
@@@ -1589,15 -1513,26 +1591,15 @@@ MODULE_DEVICE_TABLE(amba, mmci_ids)
  static struct amba_driver mmci_driver = {
        .drv            = {
                .name   = DRIVER_NAME,
 +              .pm     = &mmci_dev_pm_ops,
        },
        .probe          = mmci_probe,
        .remove         = __devexit_p(mmci_remove),
 -      .suspend        = mmci_suspend,
 -      .resume         = mmci_resume,
        .id_table       = mmci_ids,
  };
  
 -static int __init mmci_init(void)
 -{
 -      return amba_driver_register(&mmci_driver);
 -}
 -
 -static void __exit mmci_exit(void)
 -{
 -      amba_driver_unregister(&mmci_driver);
 -}
 +module_amba_driver(mmci_driver);
  
 -module_init(mmci_init);
 -module_exit(mmci_exit);
  module_param(fmax, uint, 0444);
  
  MODULE_DESCRIPTION("ARM PrimeCell PL180/181 Multimedia Card Interface driver");
index 60f205708f54660b36cacf6e1f120fad4fe3d8b8,3d00f1aab87da5ce7ff03a74f076e018e0a4546f..aafaf0b6eb1c96bcf298307b180dca75a259b424
@@@ -56,7 -56,6 +56,7 @@@
  #include <linux/mmc/sh_mmcif.h>
  #include <linux/pagemap.h>
  #include <linux/platform_device.h>
 +#include <linux/pm_qos.h>
  #include <linux/pm_runtime.h>
  #include <linux/spinlock.h>
  #include <linux/module.h>
@@@ -286,7 -285,7 +286,7 @@@ static void sh_mmcif_start_dma_rx(struc
                         DMA_FROM_DEVICE);
        if (ret > 0) {
                host->dma_active = true;
-               desc = chan->device->device_prep_slave_sg(chan, sg, ret,
+               desc = dmaengine_prep_slave_sg(chan, sg, ret,
                        DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
        }
  
@@@ -335,7 -334,7 +335,7 @@@ static void sh_mmcif_start_dma_tx(struc
                         DMA_TO_DEVICE);
        if (ret > 0) {
                host->dma_active = true;
-               desc = chan->device->device_prep_slave_sg(chan, sg, ret,
+               desc = dmaengine_prep_slave_sg(chan, sg, ret,
                        DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
        }
  
@@@ -746,6 -745,7 +746,6 @@@ static u32 sh_mmcif_set_cmd(struct sh_m
        case MMC_SET_WRITE_PROT:
        case MMC_CLR_WRITE_PROT:
        case MMC_ERASE:
 -      case MMC_GEN_CMD:
                tmp |= CMD_SET_RBSY;
                break;
        }
@@@ -828,6 -828,7 +828,6 @@@ static void sh_mmcif_start_cmd(struct s
        case MMC_SET_WRITE_PROT:
        case MMC_CLR_WRITE_PROT:
        case MMC_ERASE:
 -      case MMC_GEN_CMD:
                mask = MASK_START_CMD | MASK_MRBSYE;
                break;
        default:
@@@ -1326,7 -1327,7 +1326,7 @@@ static int __devinit sh_mmcif_probe(str
        if (ret < 0)
                goto clean_up2;
  
 -      mmc_add_host(mmc);
 +      INIT_DELAYED_WORK(&host->timeout_work, mmcif_timeout_work);
  
        sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
  
        }
        ret = request_threaded_irq(irq[1], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:int", host);
        if (ret) {
 -              free_irq(irq[0], host);
                dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n");
 -              goto clean_up3;
 +              goto clean_up4;
        }
  
 -      INIT_DELAYED_WORK(&host->timeout_work, mmcif_timeout_work);
 +      ret = mmc_add_host(mmc);
 +      if (ret < 0)
 +              goto clean_up5;
  
 -      mmc_detect_change(host->mmc, 0);
 +      dev_pm_qos_expose_latency_limit(&pdev->dev, 100);
  
        dev_info(&pdev->dev, "driver version %s\n", DRIVER_VERSION);
        dev_dbg(&pdev->dev, "chip ver H'%04x\n",
                sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0x0000ffff);
        return ret;
  
 +clean_up5:
 +      free_irq(irq[1], host);
 +clean_up4:
 +      free_irq(irq[0], host);
  clean_up3:
 -      mmc_remove_host(mmc);
        pm_runtime_suspend(&pdev->dev);
  clean_up2:
        pm_runtime_disable(&pdev->dev);
@@@ -1377,8 -1374,6 +1377,8 @@@ static int __devexit sh_mmcif_remove(st
        host->dying = true;
        pm_runtime_get_sync(&pdev->dev);
  
 +      dev_pm_qos_hide_latency_limit(&pdev->dev);
 +
        mmc_remove_host(host->mmc);
        sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
  
index 8253ec12003ed3c9001cdd7b8fed889179350d9b,def9c54f73f5861a3545f052f97a931ce164fab8..fff9286048594fa7dad59922ea382af76901450b
@@@ -34,18 -34,6 +34,18 @@@ void tmio_mmc_enable_dma(struct tmio_mm
  #endif
  }
  
 +void tmio_mmc_abort_dma(struct tmio_mmc_host *host)
 +{
 +      tmio_mmc_enable_dma(host, false);
 +
 +      if (host->chan_rx)
 +              dmaengine_terminate_all(host->chan_rx);
 +      if (host->chan_tx)
 +              dmaengine_terminate_all(host->chan_tx);
 +
 +      tmio_mmc_enable_dma(host, true);
 +}
 +
  static void tmio_mmc_start_dma_rx(struct tmio_mmc_host *host)
  {
        struct scatterlist *sg = host->sg_ptr, *sg_tmp;
@@@ -88,7 -76,7 +88,7 @@@
  
        ret = dma_map_sg(chan->device->dev, sg, host->sg_len, DMA_FROM_DEVICE);
        if (ret > 0)
-               desc = chan->device->device_prep_slave_sg(chan, sg, ret,
+               desc = dmaengine_prep_slave_sg(chan, sg, ret,
                        DMA_DEV_TO_MEM, DMA_CTRL_ACK);
  
        if (desc) {
@@@ -169,7 -157,7 +169,7 @@@ static void tmio_mmc_start_dma_tx(struc
  
        ret = dma_map_sg(chan->device->dev, sg, host->sg_len, DMA_TO_DEVICE);
        if (ret > 0)
-               desc = chan->device->device_prep_slave_sg(chan, sg, ret,
+               desc = dmaengine_prep_slave_sg(chan, sg, ret,
                        DMA_MEM_TO_DEV, DMA_CTRL_ACK);
  
        if (desc) {
index 7db6555ed3ba630f2935ce65b25200295b1754db,2a200ba0bd1a2861b765993a2e042ed78e4dab4e..590dd5cceed66164ff93686f9f355818883ac0b3
@@@ -69,19 -69,17 +69,19 @@@ static int clear_poll_bit(void __iomem 
   *  [1] enable the module.
   *  [2] reset the module.
   *
 - * In most of the cases, it's ok. But there is a hardware bug in the BCH block.
 + * In most of the cases, it's ok.
 + * But in MX23, there is a hardware bug in the BCH block (see erratum #2847).
   * If you try to soft reset the BCH block, it becomes unusable until
   * the next hard reset. This case occurs in the NAND boot mode. When the board
   * boots by NAND, the ROM of the chip will initialize the BCH blocks itself.
   * So If the driver tries to reset the BCH again, the BCH will not work anymore.
 - * You will see a DMA timeout in this case.
 + * You will see a DMA timeout in this case. The bug has been fixed
 + * in the following chips, such as MX28.
   *
   * To avoid this bug, just add a new parameter `just_enable` for
   * the mxs_reset_block(), and rewrite it here.
   */
 -int gpmi_reset_block(void __iomem *reset_addr, bool just_enable)
 +static int gpmi_reset_block(void __iomem *reset_addr, bool just_enable)
  {
        int ret;
        int timeout = 0x400;
@@@ -208,15 -206,7 +208,15 @@@ int bch_set_geometry(struct gpmi_nand_d
        if (ret)
                goto err_out;
  
 -      ret = gpmi_reset_block(r->bch_regs, true);
 +      /*
 +      * Due to erratum #2847 of the MX23, the BCH cannot be soft reset on this
 +      * chip, otherwise it will lock up. So we skip resetting BCH on the MX23.
 +      * On the other hand, the MX28 needs the reset, because one case has been
 +      * seen where the BCH produced ECC errors constantly after 10000
 +      * consecutive reboots. The latter case has not been seen on the MX23 yet,
 +      * still we don't know if it could happen there as well.
 +      */
 +      ret = gpmi_reset_block(r->bch_regs, GPMI_IS_MX23(this));
        if (ret)
                goto err_out;
  
@@@ -835,7 -825,7 +835,7 @@@ int gpmi_send_command(struct gpmi_nand_
                | BM_GPMI_CTRL0_ADDRESS_INCREMENT
                | BF_GPMI_CTRL0_XFER_COUNT(this->command_length);
        pio[1] = pio[2] = 0;
-       desc = channel->device->device_prep_slave_sg(channel,
+       desc = dmaengine_prep_slave_sg(channel,
                                        (struct scatterlist *)pio,
                                        ARRAY_SIZE(pio), DMA_TRANS_NONE, 0);
        if (!desc) {
  
        sg_init_one(sgl, this->cmd_buffer, this->command_length);
        dma_map_sg(this->dev, sgl, 1, DMA_TO_DEVICE);
-       desc = channel->device->device_prep_slave_sg(channel,
-                                       sgl, 1, DMA_MEM_TO_DEV, 1);
+       desc = dmaengine_prep_slave_sg(channel, sgl, 1, DMA_MEM_TO_DEV, 1);
        if (!desc) {
                pr_err("step 2 error\n");
                return -1;
@@@ -880,8 -869,7 +879,7 @@@ int gpmi_send_data(struct gpmi_nand_dat
                | BF_GPMI_CTRL0_ADDRESS(address)
                | BF_GPMI_CTRL0_XFER_COUNT(this->upper_len);
        pio[1] = 0;
-       desc = channel->device->device_prep_slave_sg(channel,
-                                       (struct scatterlist *)pio,
+       desc = dmaengine_prep_slave_sg(channel, (struct scatterlist *)pio,
                                        ARRAY_SIZE(pio), DMA_TRANS_NONE, 0);
        if (!desc) {
                pr_err("step 1 error\n");
  
        /* [2] send DMA request */
        prepare_data_dma(this, DMA_TO_DEVICE);
-       desc = channel->device->device_prep_slave_sg(channel, &this->data_sgl,
+       desc = dmaengine_prep_slave_sg(channel, &this->data_sgl,
                                                1, DMA_MEM_TO_DEV, 1);
        if (!desc) {
                pr_err("step 2 error\n");
@@@ -916,7 -904,7 +914,7 @@@ int gpmi_read_data(struct gpmi_nand_dat
                | BF_GPMI_CTRL0_ADDRESS(BV_GPMI_CTRL0_ADDRESS__NAND_DATA)
                | BF_GPMI_CTRL0_XFER_COUNT(this->upper_len);
        pio[1] = 0;
-       desc = channel->device->device_prep_slave_sg(channel,
+       desc = dmaengine_prep_slave_sg(channel,
                                        (struct scatterlist *)pio,
                                        ARRAY_SIZE(pio), DMA_TRANS_NONE, 0);
        if (!desc) {
  
        /* [2] : send DMA request */
        prepare_data_dma(this, DMA_FROM_DEVICE);
-       desc = channel->device->device_prep_slave_sg(channel, &this->data_sgl,
-                                               1, DMA_DEV_TO_MEM, 1);
+       desc = dmaengine_prep_slave_sg(channel, &this->data_sgl,
+                                       1, DMA_DEV_TO_MEM, 1);
        if (!desc) {
                pr_err("step 2 error\n");
                return -1;
@@@ -972,8 -960,7 +970,7 @@@ int gpmi_send_page(struct gpmi_nand_dat
        pio[4] = payload;
        pio[5] = auxiliary;
  
-       desc = channel->device->device_prep_slave_sg(channel,
-                                       (struct scatterlist *)pio,
+       desc = dmaengine_prep_slave_sg(channel, (struct scatterlist *)pio,
                                        ARRAY_SIZE(pio), DMA_TRANS_NONE, 0);
        if (!desc) {
                pr_err("step 2 error\n");
@@@ -1007,7 -994,7 +1004,7 @@@ int gpmi_read_page(struct gpmi_nand_dat
                | BF_GPMI_CTRL0_ADDRESS(address)
                | BF_GPMI_CTRL0_XFER_COUNT(0);
        pio[1] = 0;
-       desc = channel->device->device_prep_slave_sg(channel,
+       desc = dmaengine_prep_slave_sg(channel,
                                (struct scatterlist *)pio, 2,
                                DMA_TRANS_NONE, 0);
        if (!desc) {
        pio[3] = geo->page_size;
        pio[4] = payload;
        pio[5] = auxiliary;
-       desc = channel->device->device_prep_slave_sg(channel,
+       desc = dmaengine_prep_slave_sg(channel,
                                        (struct scatterlist *)pio,
                                        ARRAY_SIZE(pio), DMA_TRANS_NONE, 1);
        if (!desc) {
                | BF_GPMI_CTRL0_ADDRESS(address)
                | BF_GPMI_CTRL0_XFER_COUNT(geo->page_size);
        pio[1] = 0;
-       desc = channel->device->device_prep_slave_sg(channel,
+       desc = dmaengine_prep_slave_sg(channel,
                                (struct scatterlist *)pio, 2,
                                DMA_TRANS_NONE, 1);
        if (!desc) {
index 0686b93f1857a911db624c9bf5c1818475b3b031,554fef3f0130636786eb411fd3179d1206d3e51b..f84dd2dc82b6181605bd74250eddf07593644095
@@@ -458,7 -458,7 +458,7 @@@ static int ks8842_tx_frame_dma(struct s
        if (sg_dma_len(&ctl->sg) % 4)
                sg_dma_len(&ctl->sg) += 4 - sg_dma_len(&ctl->sg) % 4;
  
-       ctl->adesc = ctl->chan->device->device_prep_slave_sg(ctl->chan,
+       ctl->adesc = dmaengine_prep_slave_sg(ctl->chan,
                &ctl->sg, 1, DMA_MEM_TO_DEV,
                DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP);
        if (!ctl->adesc)
@@@ -570,7 -570,7 +570,7 @@@ static int __ks8842_start_new_rx_dma(st
  
                sg_dma_len(sg) = DMA_BUFFER_SIZE;
  
-               ctl->adesc = ctl->chan->device->device_prep_slave_sg(ctl->chan,
+               ctl->adesc = dmaengine_prep_slave_sg(ctl->chan,
                        sg, 1, DMA_DEV_TO_MEM,
                        DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP);
  
@@@ -1080,7 -1080,6 +1080,7 @@@ static int ks8842_set_mac(struct net_de
        if (!is_valid_ether_addr(addr->sa_data))
                return -EADDRNOTAVAIL;
  
 +      netdev->addr_assign_type &= ~NET_ADDR_RANDOM;
        memcpy(netdev->dev_addr, mac, netdev->addr_len);
  
        ks8842_write_mac_addr(adapter, mac);
@@@ -1212,7 -1211,7 +1212,7 @@@ static int __devinit ks8842_probe(struc
                ks8842_read_mac_addr(adapter, netdev->dev_addr);
  
                if (!is_valid_ether_addr(netdev->dev_addr))
 -                      random_ether_addr(netdev->dev_addr);
 +                      eth_hw_addr_random(netdev);
        }
  
        id = ks8842_read16(adapter, 32, REG_SW_ID_AND_ENABLE);
diff --combined drivers/spi/spi-pl022.c
index dc8485d1e883adfa10fcded8710c2a8007ba991a,a209f3b7b05be2373a9b8056c26ecb3a2a1f9a3f..96f0da66b185b5cbb41c6cdf01d7e969e5b341ed
@@@ -29,6 -29,7 +29,6 @@@
  #include <linux/errno.h>
  #include <linux/interrupt.h>
  #include <linux/spi/spi.h>
 -#include <linux/workqueue.h>
  #include <linux/delay.h>
  #include <linux/clk.h>
  #include <linux/err.h>
@@@ -329,13 -330,12 +329,13 @@@ struct vendor_data 
   * @clk: outgoing clock "SPICLK" for the SPI bus
   * @master: SPI framework hookup
   * @master_info: controller-specific data from machine setup
 - * @workqueue: a workqueue on which any spi_message request is queued
 - * @pump_messages: work struct for scheduling work to the workqueue
 + * @kworker: thread struct for message pump
 + * @kworker_task: pointer to task for message pump kworker thread
 + * @pump_messages: work struct for scheduling work to the message pump
   * @queue_lock: spinlock to syncronise access to message queue
   * @queue: message queue
 - * @busy: workqueue is busy
 - * @running: workqueue is running
 + * @busy: message pump is busy
 + * @running: message pump is running
   * @pump_transfers: Tasklet used in Interrupt Transfer mode
   * @cur_msg: Pointer to current spi_message being processed
   * @cur_transfer: Pointer to current spi_transfer
@@@ -365,7 -365,14 +365,7 @@@ struct pl022 
        struct clk                      *clk;
        struct spi_master               *master;
        struct pl022_ssp_controller     *master_info;
 -      /* Driver message queue */
 -      struct workqueue_struct         *workqueue;
 -      struct work_struct              pump_messages;
 -      spinlock_t                      queue_lock;
 -      struct list_head                queue;
 -      bool                            busy;
 -      bool                            running;
 -      /* Message transfer pump */
 +      /* Message per-transfer pump */
        struct tasklet_struct           pump_transfers;
        struct spi_message              *cur_msg;
        struct spi_transfer             *cur_transfer;
        struct sg_table                 sgt_rx;
        struct sg_table                 sgt_tx;
        char                            *dummypage;
 +      bool                            dma_running;
  #endif
  };
  
@@@ -442,6 -448,8 +442,6 @@@ static void null_cs_control(u32 command
  static void giveback(struct pl022 *pl022)
  {
        struct spi_transfer *last_transfer;
 -      unsigned long flags;
 -      struct spi_message *msg;
        pl022->next_msg_cs_active = false;
  
        last_transfer = list_entry(pl022->cur_msg->transfers.prev,
                 * sent the current message could be unloaded, which
                 * could invalidate the cs_control() callback...
                 */
 -
                /* get a pointer to the next message, if any */
 -              spin_lock_irqsave(&pl022->queue_lock, flags);
 -              if (list_empty(&pl022->queue))
 -                      next_msg = NULL;
 -              else
 -                      next_msg = list_entry(pl022->queue.next,
 -                                      struct spi_message, queue);
 -              spin_unlock_irqrestore(&pl022->queue_lock, flags);
 +              next_msg = spi_get_next_queued_message(pl022->master);
  
                /*
                 * see if the next and current messages point
                        pl022->cur_chip->cs_control(SSP_CHIP_DESELECT);
                else
                        pl022->next_msg_cs_active = true;
 +
        }
  
 -      spin_lock_irqsave(&pl022->queue_lock, flags);
 -      msg = pl022->cur_msg;
        pl022->cur_msg = NULL;
        pl022->cur_transfer = NULL;
        pl022->cur_chip = NULL;
 -      queue_work(pl022->workqueue, &pl022->pump_messages);
 -      spin_unlock_irqrestore(&pl022->queue_lock, flags);
 -
 -      msg->state = NULL;
 -      if (msg->complete)
 -              msg->complete(msg->context);
 +      spi_finalize_current_message(pl022->master);
  }
  
  /**
@@@ -880,10 -901,12 +880,12 @@@ static int configure_dma(struct pl022 *
        struct dma_slave_config rx_conf = {
                .src_addr = SSP_DR(pl022->phybase),
                .direction = DMA_DEV_TO_MEM,
+               .device_fc = false,
        };
        struct dma_slave_config tx_conf = {
                .dst_addr = SSP_DR(pl022->phybase),
                .direction = DMA_MEM_TO_DEV,
+               .device_fc = false,
        };
        unsigned int pages;
        int ret;
                goto err_tx_sgmap;
  
        /* Send both scatterlists */
-       rxdesc = rxchan->device->device_prep_slave_sg(rxchan,
+       rxdesc = dmaengine_prep_slave_sg(rxchan,
                                      pl022->sgt_rx.sgl,
                                      rx_sglen,
                                      DMA_DEV_TO_MEM,
        if (!rxdesc)
                goto err_rxdesc;
  
-       txdesc = txchan->device->device_prep_slave_sg(txchan,
+       txdesc = dmaengine_prep_slave_sg(txchan,
                                      pl022->sgt_tx.sgl,
                                      tx_sglen,
                                      DMA_MEM_TO_DEV,
        dmaengine_submit(txdesc);
        dma_async_issue_pending(rxchan);
        dma_async_issue_pending(txchan);
 +      pl022->dma_running = true;
  
        return 0;
  
@@@ -1063,7 -1085,7 +1065,7 @@@ err_alloc_rx_sg
        return -ENOMEM;
  }
  
 -static int __init pl022_dma_probe(struct pl022 *pl022)
 +static int __devinit pl022_dma_probe(struct pl022 *pl022)
  {
        dma_cap_mask_t mask;
  
@@@ -1121,12 -1143,11 +1123,12 @@@ static void terminate_dma(struct pl022 
        dmaengine_terminate_all(rxchan);
        dmaengine_terminate_all(txchan);
        unmap_free_dma_scatter(pl022);
 +      pl022->dma_running = false;
  }
  
  static void pl022_dma_remove(struct pl022 *pl022)
  {
 -      if (pl022->busy)
 +      if (pl022->dma_running)
                terminate_dma(pl022);
        if (pl022->dma_tx_channel)
                dma_release_channel(pl022->dma_tx_channel);
        return;
  }
  
 -/**
 - * pump_messages - Workqueue function which processes spi message queue
 - * @data: pointer to private data of SSP driver
 - *
 - * This function checks if there is any spi message in the queue that
 - * needs processing and delegate control to appropriate function
 - * do_polling_transfer()/do_interrupt_dma_transfer()
 - * based on the kind of the transfer
 - *
 - */
 -static void pump_messages(struct work_struct *work)
 +static int pl022_transfer_one_message(struct spi_master *master,
 +                                    struct spi_message *msg)
  {
 -      struct pl022 *pl022 =
 -              container_of(work, struct pl022, pump_messages);
 -      unsigned long flags;
 -      bool was_busy = false;
 -
 -      /* Lock queue and check for queue work */
 -      spin_lock_irqsave(&pl022->queue_lock, flags);
 -      if (list_empty(&pl022->queue) || !pl022->running) {
 -              if (pl022->busy) {
 -                      /* nothing more to do - disable spi/ssp and power off */
 -                      writew((readw(SSP_CR1(pl022->virtbase)) &
 -                              (~SSP_CR1_MASK_SSE)), SSP_CR1(pl022->virtbase));
 -
 -                      if (pl022->master_info->autosuspend_delay > 0) {
 -                              pm_runtime_mark_last_busy(&pl022->adev->dev);
 -                              pm_runtime_put_autosuspend(&pl022->adev->dev);
 -                      } else {
 -                              pm_runtime_put(&pl022->adev->dev);
 -                      }
 -              }
 -              pl022->busy = false;
 -              spin_unlock_irqrestore(&pl022->queue_lock, flags);
 -              return;
 -      }
 -
 -      /* Make sure we are not already running a message */
 -      if (pl022->cur_msg) {
 -              spin_unlock_irqrestore(&pl022->queue_lock, flags);
 -              return;
 -      }
 -      /* Extract head of queue */
 -      pl022->cur_msg =
 -          list_entry(pl022->queue.next, struct spi_message, queue);
 -
 -      list_del_init(&pl022->cur_msg->queue);
 -      if (pl022->busy)
 -              was_busy = true;
 -      else
 -              pl022->busy = true;
 -      spin_unlock_irqrestore(&pl022->queue_lock, flags);
 +      struct pl022 *pl022 = spi_master_get_devdata(master);
  
        /* Initial message state */
 -      pl022->cur_msg->state = STATE_START;
 -      pl022->cur_transfer = list_entry(pl022->cur_msg->transfers.next,
 -                                          struct spi_transfer, transfer_list);
 +      pl022->cur_msg = msg;
 +      msg->state = STATE_START;
 +
 +      pl022->cur_transfer = list_entry(msg->transfers.next,
 +                                       struct spi_transfer, transfer_list);
  
        /* Setup the SPI using the per chip configuration */
 -      pl022->cur_chip = spi_get_ctldata(pl022->cur_msg->spi);
 -      if (!was_busy)
 -              /*
 -               * We enable the core voltage and clocks here, then the clocks
 -               * and core will be disabled when this workqueue is run again
 -               * and there is no more work to be done.
 -               */
 -              pm_runtime_get_sync(&pl022->adev->dev);
 +      pl022->cur_chip = spi_get_ctldata(msg->spi);
  
        restore_state(pl022);
        flush(pl022);
                do_polling_transfer(pl022);
        else
                do_interrupt_dma_transfer(pl022);
 -}
 -
 -static int __init init_queue(struct pl022 *pl022)
 -{
 -      INIT_LIST_HEAD(&pl022->queue);
 -      spin_lock_init(&pl022->queue_lock);
 -
 -      pl022->running = false;
 -      pl022->busy = false;
 -
 -      tasklet_init(&pl022->pump_transfers, pump_transfers,
 -                      (unsigned long)pl022);
 -
 -      INIT_WORK(&pl022->pump_messages, pump_messages);
 -      pl022->workqueue = create_singlethread_workqueue(
 -                                      dev_name(pl022->master->dev.parent));
 -      if (pl022->workqueue == NULL)
 -              return -EBUSY;
  
        return 0;
  }
  
 -static int start_queue(struct pl022 *pl022)
 +static int pl022_prepare_transfer_hardware(struct spi_master *master)
  {
 -      unsigned long flags;
 -
 -      spin_lock_irqsave(&pl022->queue_lock, flags);
 -
 -      if (pl022->running || pl022->busy) {
 -              spin_unlock_irqrestore(&pl022->queue_lock, flags);
 -              return -EBUSY;
 -      }
 -
 -      pl022->running = true;
 -      pl022->cur_msg = NULL;
 -      pl022->cur_transfer = NULL;
 -      pl022->cur_chip = NULL;
 -      pl022->next_msg_cs_active = false;
 -      spin_unlock_irqrestore(&pl022->queue_lock, flags);
 -
 -      queue_work(pl022->workqueue, &pl022->pump_messages);
 +      struct pl022 *pl022 = spi_master_get_devdata(master);
  
 +      /*
 +       * Just make sure we have all we need to run the transfer by syncing
 +       * with the runtime PM framework.
 +       */
 +      pm_runtime_get_sync(&pl022->adev->dev);
        return 0;
  }
  
 -static int stop_queue(struct pl022 *pl022)
 +static int pl022_unprepare_transfer_hardware(struct spi_master *master)
  {
 -      unsigned long flags;
 -      unsigned limit = 500;
 -      int status = 0;
 +      struct pl022 *pl022 = spi_master_get_devdata(master);
  
 -      spin_lock_irqsave(&pl022->queue_lock, flags);
 +      /* nothing more to do - disable spi/ssp and power off */
 +      writew((readw(SSP_CR1(pl022->virtbase)) &
 +              (~SSP_CR1_MASK_SSE)), SSP_CR1(pl022->virtbase));
  
 -      /* This is a bit lame, but is optimized for the common execution path.
 -       * A wait_queue on the pl022->busy could be used, but then the common
 -       * execution path (pump_messages) would be required to call wake_up or
 -       * friends on every SPI message. Do this instead */
 -      while ((!list_empty(&pl022->queue) || pl022->busy) && limit--) {
 -              spin_unlock_irqrestore(&pl022->queue_lock, flags);
 -              msleep(10);
 -              spin_lock_irqsave(&pl022->queue_lock, flags);
 +      if (pl022->master_info->autosuspend_delay > 0) {
 +              pm_runtime_mark_last_busy(&pl022->adev->dev);
 +              pm_runtime_put_autosuspend(&pl022->adev->dev);
 +      } else {
 +              pm_runtime_put(&pl022->adev->dev);
        }
  
 -      if (!list_empty(&pl022->queue) || pl022->busy)
 -              status = -EBUSY;
 -      else
 -              pl022->running = false;
 -
 -      spin_unlock_irqrestore(&pl022->queue_lock, flags);
 -
 -      return status;
 -}
 -
 -static int destroy_queue(struct pl022 *pl022)
 -{
 -      int status;
 -
 -      status = stop_queue(pl022);
 -      /* we are unloading the module or failing to load (only two calls
 -       * to this routine), and neither call can handle a return value.
 -       * However, destroy_workqueue calls flush_workqueue, and that will
 -       * block until all work is done.  If the reason that stop_queue
 -       * timed out is that the work will never finish, then it does no
 -       * good to call destroy_workqueue, so return anyway. */
 -      if (status != 0)
 -              return status;
 -
 -      destroy_workqueue(pl022->workqueue);
 -
        return 0;
  }
  
@@@ -1646,6 -1778,38 +1648,6 @@@ static int verify_controller_parameters
        return 0;
  }
  
 -/**
 - * pl022_transfer - transfer function registered to SPI master framework
 - * @spi: spi device which is requesting transfer
 - * @msg: spi message which is to handled is queued to driver queue
 - *
 - * This function is registered to the SPI framework for this SPI master
 - * controller. It will queue the spi_message in the queue of driver if
 - * the queue is not stopped and return.
 - */
 -static int pl022_transfer(struct spi_device *spi, struct spi_message *msg)
 -{
 -      struct pl022 *pl022 = spi_master_get_devdata(spi->master);
 -      unsigned long flags;
 -
 -      spin_lock_irqsave(&pl022->queue_lock, flags);
 -
 -      if (!pl022->running) {
 -              spin_unlock_irqrestore(&pl022->queue_lock, flags);
 -              return -ESHUTDOWN;
 -      }
 -      msg->actual_length = 0;
 -      msg->status = -EINPROGRESS;
 -      msg->state = STATE_START;
 -
 -      list_add_tail(&msg->queue, &pl022->queue);
 -      if (pl022->running && !pl022->busy)
 -              queue_work(pl022->workqueue, &pl022->pump_messages);
 -
 -      spin_unlock_irqrestore(&pl022->queue_lock, flags);
 -      return 0;
 -}
 -
  static inline u32 spi_rate(u32 rate, u16 cpsdvsr, u16 scr)
  {
        return rate / (cpsdvsr * (1 + scr));
@@@ -2008,10 -2172,7 +2010,10 @@@ pl022_probe(struct amba_device *adev, c
        master->num_chipselect = platform_info->num_chipselect;
        master->cleanup = pl022_cleanup;
        master->setup = pl022_setup;
 -      master->transfer = pl022_transfer;
 +      master->prepare_transfer_hardware = pl022_prepare_transfer_hardware;
 +      master->transfer_one_message = pl022_transfer_one_message;
 +      master->unprepare_transfer_hardware = pl022_unprepare_transfer_hardware;
 +      master->rt = platform_info->rt;
  
        /*
         * Supports mode 0-3, loopback, and active low CS. Transfers are
                goto err_no_clk_en;
        }
  
 +      /* Initialize transfer pump */
 +      tasklet_init(&pl022->pump_transfers, pump_transfers,
 +                   (unsigned long)pl022);
 +
        /* Disable SSP */
        writew((readw(SSP_CR1(pl022->virtbase)) & (~SSP_CR1_MASK_SSE)),
               SSP_CR1(pl022->virtbase));
                        platform_info->enable_dma = 0;
        }
  
 -      /* Initialize and start queue */
 -      status = init_queue(pl022);
 -      if (status != 0) {
 -              dev_err(&adev->dev, "probe - problem initializing queue\n");
 -              goto err_init_queue;
 -      }
 -      status = start_queue(pl022);
 -      if (status != 0) {
 -              dev_err(&adev->dev, "probe - problem starting queue\n");
 -              goto err_start_queue;
 -      }
        /* Register with the SPI framework */
        amba_set_drvdata(adev, pl022);
        status = spi_register_master(master);
        return 0;
  
   err_spi_register:
 - err_start_queue:
 - err_init_queue:
 -      destroy_queue(pl022);
        if (platform_info->enable_dma)
                pl022_dma_remove(pl022);
  
@@@ -2138,6 -2309,9 +2140,6 @@@ pl022_remove(struct amba_device *adev
         */
        pm_runtime_get_noresume(&adev->dev);
  
 -      /* Remove the queue */
 -      if (destroy_queue(pl022) != 0)
 -              dev_err(&adev->dev, "queue remove failed\n");
        load_ssp_default_config(pl022);
        if (pl022->master_info->enable_dma)
                pl022_dma_remove(pl022);
  static int pl022_suspend(struct device *dev)
  {
        struct pl022 *pl022 = dev_get_drvdata(dev);
 -      int status = 0;
 +      int ret;
  
 -      status = stop_queue(pl022);
 -      if (status) {
 -              dev_warn(dev, "suspend cannot stop queue\n");
 -              return status;
 +      ret = spi_master_suspend(pl022->master);
 +      if (ret) {
 +              dev_warn(dev, "cannot suspend master\n");
 +              return ret;
        }
  
        dev_dbg(dev, "suspended\n");
  static int pl022_resume(struct device *dev)
  {
        struct pl022 *pl022 = dev_get_drvdata(dev);
 -      int status = 0;
 +      int ret;
  
        /* Start the queue running */
 -      status = start_queue(pl022);
 -      if (status)
 -              dev_err(dev, "problem starting queue (%d)\n", status);
 +      ret = spi_master_resume(pl022->master);
 +      if (ret)
 +              dev_err(dev, "problem starting queue (%d)\n", ret);
        else
                dev_dbg(dev, "resumed\n");
  
 -      return status;
 +      return ret;
  }
  #endif        /* CONFIG_PM */
  
index 5c6fa5ed3366fef69b7cef2b8b49ce67a0620935,ea4c8d57667aae7324970d115eb14ace12b16461..ec47d3bdfd13233b68774e59fedf6b77570c3c16
@@@ -196,7 -196,6 +196,7 @@@ struct pch_spi_data 
        struct pch_spi_dma_ctrl dma;
        int use_dma;
        u8 irq_reg_sts;
 +      int save_total_len;
  };
  
  /**
@@@ -217,7 -216,7 +217,7 @@@ struct pch_pd_dev_save 
        struct pch_spi_board_data *board_dat;
  };
  
 -static struct pci_device_id pch_spi_pcidev_id[] = {
 +static DEFINE_PCI_DEVICE_TABLE(pch_spi_pcidev_id) = {
        { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_GE_SPI),    1, },
        { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_SPI), 2, },
        { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7223_SPI), 1, },
@@@ -319,23 -318,22 +319,23 @@@ static void pch_spi_handler_sub(struct 
                data->tx_index = tx_index;
                data->rx_index = rx_index;
  
 -      }
 -
 -      /* if transfer complete interrupt */
 -      if (reg_spsr_val & SPSR_FI_BIT) {
 -              if ((tx_index == bpw_len) && (rx_index == tx_index)) {
 -                      /* disable interrupts */
 -                      pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL);
 -
 -                      /* transfer is completed;
 -                         inform pch_spi_process_messages */
 -                      data->transfer_complete = true;
 -                      data->transfer_active = false;
 -                      wake_up(&data->wait);
 -              } else {
 -                      dev_err(&data->master->dev,
 -                              "%s : Transfer is not completed", __func__);
 +              /* if transfer complete interrupt */
 +              if (reg_spsr_val & SPSR_FI_BIT) {
 +                      if ((tx_index == bpw_len) && (rx_index == tx_index)) {
 +                              /* disable interrupts */
 +                              pch_spi_setclr_reg(data->master, PCH_SPCR, 0,
 +                                                 PCH_ALL);
 +
 +                              /* transfer is completed;
 +                                 inform pch_spi_process_messages */
 +                              data->transfer_complete = true;
 +                              data->transfer_active = false;
 +                              wake_up(&data->wait);
 +                      } else {
 +                              dev_err(&data->master->dev,
 +                                      "%s : Transfer is not completed",
 +                                      __func__);
 +                      }
                }
        }
  }
@@@ -824,13 -822,11 +824,13 @@@ static void pch_spi_copy_rx_data_for_dm
                rx_dma_buf = data->dma.rx_buf_virt;
                for (j = 0; j < data->bpw_len; j++)
                        *rx_buf++ = *rx_dma_buf++ & 0xFF;
 +              data->cur_trans->rx_buf = rx_buf;
        } else {
                rx_sbuf = data->cur_trans->rx_buf;
                rx_dma_sbuf = data->dma.rx_buf_virt;
                for (j = 0; j < data->bpw_len; j++)
                        *rx_sbuf++ = *rx_dma_sbuf++;
 +              data->cur_trans->rx_buf = rx_sbuf;
        }
  }
  
@@@ -856,9 -852,6 +856,9 @@@ static int pch_spi_start_transfer(struc
        rtn = wait_event_interruptible_timeout(data->wait,
                                               data->transfer_complete,
                                               msecs_to_jiffies(2 * HZ));
 +      if (!rtn)
 +              dev_err(&data->master->dev,
 +                      "%s wait-event timeout\n", __func__);
  
        dma_sync_sg_for_cpu(&data->master->dev, dma->sg_rx_p, dma->nent,
                            DMA_FROM_DEVICE);
@@@ -930,8 -923,7 +930,8 @@@ static void pch_spi_request_dma(struct 
        dma_cap_set(DMA_SLAVE, mask);
  
        /* Get DMA's dev information */
 -      dma_dev = pci_get_bus_and_slot(2, PCI_DEVFN(12, 0));
 +      dma_dev = pci_get_bus_and_slot(data->board_dat->pdev->bus->number,
 +                                     PCI_DEVFN(12, 0));
  
        /* Set Tx DMA */
        param = &dma->param_tx;
@@@ -995,7 -987,6 +995,7 @@@ static void pch_spi_handle_dma(struct p
        int i;
        int size;
        int rem;
 +      int head;
        unsigned long flags;
        struct pch_spi_dma_ctrl *dma;
  
        }
        data->bpw_len = data->cur_trans->len / (*bpw / 8);
  
 +      if (data->bpw_len > PCH_BUF_SIZE) {
 +              data->bpw_len = PCH_BUF_SIZE;
 +              data->cur_trans->len -= PCH_BUF_SIZE;
 +      }
 +
        /* copy Tx Data */
        if (data->cur_trans->tx_buf != NULL) {
                if (*bpw == 8) {
                                *tx_dma_sbuf++ = *tx_sbuf++;
                }
        }
 +
 +      /* Calculate Rx parameter for DMA transmitting */
        if (data->bpw_len > PCH_DMA_TRANS_SIZE) {
 -              num = data->bpw_len / PCH_DMA_TRANS_SIZE + 1;
 +              if (data->bpw_len % PCH_DMA_TRANS_SIZE) {
 +                      num = data->bpw_len / PCH_DMA_TRANS_SIZE + 1;
 +                      rem = data->bpw_len % PCH_DMA_TRANS_SIZE;
 +              } else {
 +                      num = data->bpw_len / PCH_DMA_TRANS_SIZE;
 +                      rem = PCH_DMA_TRANS_SIZE;
 +              }
                size = PCH_DMA_TRANS_SIZE;
 -              rem = data->bpw_len % PCH_DMA_TRANS_SIZE;
        } else {
                num = 1;
                size = data->bpw_len;
                sg_dma_address(sg) = dma->rx_buf_dma + sg->offset;
        }
        sg = dma->sg_rx_p;
-       desc_rx = dma->chan_rx->device->device_prep_slave_sg(dma->chan_rx, sg,
+       desc_rx = dmaengine_prep_slave_sg(dma->chan_rx, sg,
                                        num, DMA_DEV_TO_MEM,
                                        DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
        if (!desc_rx) {
        dma->nent = num;
        dma->desc_rx = desc_rx;
  
 -      /* TX */
 -      if (data->bpw_len > PCH_DMA_TRANS_SIZE) {
 -              num = data->bpw_len / PCH_DMA_TRANS_SIZE;
 +      /* Calculate Tx parameter for DMA transmitting */
 +      if (data->bpw_len > PCH_MAX_FIFO_DEPTH) {
 +              head = PCH_MAX_FIFO_DEPTH - PCH_DMA_TRANS_SIZE;
 +              if (data->bpw_len % PCH_DMA_TRANS_SIZE > 4) {
 +                      num = data->bpw_len / PCH_DMA_TRANS_SIZE + 1;
 +                      rem = data->bpw_len % PCH_DMA_TRANS_SIZE - head;
 +              } else {
 +                      num = data->bpw_len / PCH_DMA_TRANS_SIZE;
 +                      rem = data->bpw_len % PCH_DMA_TRANS_SIZE +
 +                            PCH_DMA_TRANS_SIZE - head;
 +              }
                size = PCH_DMA_TRANS_SIZE;
 -              rem = 16;
        } else {
                num = 1;
                size = data->bpw_len;
                rem = data->bpw_len;
 +              head = 0;
        }
  
        dma->sg_tx_p = kzalloc(sizeof(struct scatterlist)*num, GFP_ATOMIC);
        for (i = 0; i < num; i++, sg++) {
                if (i == 0) {
                        sg->offset = 0;
 +                      sg_set_page(sg, virt_to_page(dma->tx_buf_virt), size + head,
 +                                  sg->offset);
 +                      sg_dma_len(sg) = size + head;
 +              } else if (i == (num - 1)) {
 +                      sg->offset = head + size * i;
 +                      sg->offset = sg->offset * (*bpw / 8);
                        sg_set_page(sg, virt_to_page(dma->tx_buf_virt), rem,
                                    sg->offset);
                        sg_dma_len(sg) = rem;
                } else {
 -                      sg->offset = rem + size * (i - 1);
 +                      sg->offset = head + size * i;
                        sg->offset = sg->offset * (*bpw / 8);
                        sg_set_page(sg, virt_to_page(dma->tx_buf_virt), size,
                                    sg->offset);
                sg_dma_address(sg) = dma->tx_buf_dma + sg->offset;
        }
        sg = dma->sg_tx_p;
-       desc_tx = dma->chan_tx->device->device_prep_slave_sg(dma->chan_tx,
+       desc_tx = dmaengine_prep_slave_sg(dma->chan_tx,
                                        sg, num, DMA_MEM_TO_DEV,
                                        DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
        if (!desc_tx) {
@@@ -1237,7 -1202,6 +1237,7 @@@ static void pch_spi_process_messages(st
                                    data->current_msg->spi->bits_per_word);
        pch_spi_writereg(data->master, PCH_SSNXCR, SSN_NO_CONTROL);
        do {
 +              int cnt;
                /* If we are already processing a message get the next
                transfer structure from the message otherwise retrieve
                the 1st transfer request from the message. */
                }
                spin_unlock(&data->lock);
  
 +              if (!data->cur_trans->len)
 +                      goto out;
 +              cnt = (data->cur_trans->len - 1) / PCH_BUF_SIZE + 1;
 +              data->save_total_len = data->cur_trans->len;
                if (data->use_dma) {
 -                      pch_spi_handle_dma(data, &bpw);
 -                      if (!pch_spi_start_transfer(data))
 -                              goto out;
 -                      pch_spi_copy_rx_data_for_dma(data, bpw);
 +                      int i;
 +                      char *save_rx_buf = data->cur_trans->rx_buf;
 +                      for (i = 0; i < cnt; i ++) {
 +                              pch_spi_handle_dma(data, &bpw);
 +                              if (!pch_spi_start_transfer(data)) {
 +                                      data->transfer_complete = true;
 +                                      data->current_msg->status = -EIO;
 +                                      data->current_msg->complete
 +                                                 (data->current_msg->context);
 +                                      data->bcurrent_msg_processing = false;
 +                                      data->current_msg = NULL;
 +                                      data->cur_trans = NULL;
 +                                      goto out;
 +                              }
 +                              pch_spi_copy_rx_data_for_dma(data, bpw);
 +                      }
 +                      data->cur_trans->rx_buf = save_rx_buf;
                } else {
                        pch_spi_set_tx(data, &bpw);
                        pch_spi_set_ir(data);
                        data->pkt_tx_buff = NULL;
                }
                /* increment message count */
 +              data->cur_trans->len = data->save_total_len;
                data->current_msg->actual_length += data->cur_trans->len;
  
                dev_dbg(&data->master->dev,
@@@ -1442,7 -1388,6 +1442,7 @@@ static int __devinit pch_spi_pd_probe(s
        master->num_chipselect = PCH_MAX_CS;
        master->setup = pch_spi_setup;
        master->transfer = pch_spi_transfer;
 +      master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
  
        data->board_dat = board_dat;
        data->plat_dev = plat_dev;
@@@ -1775,7 -1720,7 +1775,7 @@@ static int pch_spi_resume(struct pci_de
  
  #endif
  
 -static struct pci_driver pch_spi_pcidev = {
 +static struct pci_driver pch_spi_pcidev_driver = {
        .name = "pch_spi",
        .id_table = pch_spi_pcidev_id,
        .probe = pch_spi_probe,
@@@ -1791,7 -1736,7 +1791,7 @@@ static int __init pch_spi_init(void
        if (ret)
                return ret;
  
 -      ret = pci_register_driver(&pch_spi_pcidev);
 +      ret = pci_register_driver(&pch_spi_pcidev_driver);
        if (ret)
                return ret;
  
@@@ -1801,7 -1746,7 +1801,7 @@@ module_init(pch_spi_init)
  
  static void __exit pch_spi_exit(void)
  {
 -      pci_unregister_driver(&pch_spi_pcidev);
 +      pci_unregister_driver(&pch_spi_pcidev_driver);
        platform_driver_unregister(&pch_spi_pd_driver);
  }
  module_exit(pch_spi_exit);
index 20d795d9b59104329d96ddf9e113877cf693b0a7,f9dcb5379b92c5cda3ff32a9463bcae1283ef3b6..0c65c9e669867bf70ed3c86e61e06b3846bf5b60
@@@ -51,6 -51,7 +51,7 @@@
  #include <linux/dma-mapping.h>
  #include <linux/scatterlist.h>
  #include <linux/delay.h>
+ #include <linux/types.h>
  
  #include <asm/io.h>
  #include <asm/sizes.h>
@@@ -159,7 -160,6 +160,7 @@@ struct uart_amba_port 
        unsigned int            fifosize;       /* vendor-specific */
        unsigned int            lcrh_tx;        /* vendor-specific */
        unsigned int            lcrh_rx;        /* vendor-specific */
 +      unsigned int            old_cr;         /* state during shutdown */
        bool                    autorts;
        char                    type[12];
        bool                    interrupt_may_hang; /* vendor-specific */
@@@ -271,6 -271,7 +272,7 @@@ static void pl011_dma_probe_initcall(st
                .dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE,
                .direction = DMA_MEM_TO_DEV,
                .dst_maxburst = uap->fifosize >> 1,
+               .device_fc = false,
        };
        struct dma_chan *chan;
        dma_cap_mask_t mask;
                        .src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE,
                        .direction = DMA_DEV_TO_MEM,
                        .src_maxburst = uap->fifosize >> 1,
+                       .device_fc = false,
                };
  
                chan = dma_request_channel(mask, plat->dma_filter, plat->dma_rx_param);
@@@ -481,7 -483,7 +484,7 @@@ static int pl011_dma_tx_refill(struct u
                return -EBUSY;
        }
  
-       desc = dma_dev->device_prep_slave_sg(chan, &dmatx->sg, 1, DMA_MEM_TO_DEV,
+       desc = dmaengine_prep_slave_sg(chan, &dmatx->sg, 1, DMA_MEM_TO_DEV,
                                             DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
        if (!desc) {
                dma_unmap_sg(dma_dev->dev, &dmatx->sg, 1, DMA_TO_DEVICE);
@@@ -664,7 -666,6 +667,6 @@@ static void pl011_dma_rx_callback(void 
  static int pl011_dma_rx_trigger_dma(struct uart_amba_port *uap)
  {
        struct dma_chan *rxchan = uap->dmarx.chan;
-       struct dma_device *dma_dev;
        struct pl011_dmarx_data *dmarx = &uap->dmarx;
        struct dma_async_tx_descriptor *desc;
        struct pl011_sgbuf *sgbuf;
        /* Start the RX DMA job */
        sgbuf = uap->dmarx.use_buf_b ?
                &uap->dmarx.sgbuf_b : &uap->dmarx.sgbuf_a;
-       dma_dev = rxchan->device;
-       desc = rxchan->device->device_prep_slave_sg(rxchan, &sgbuf->sg, 1,
+       desc = dmaengine_prep_slave_sg(rxchan, &sgbuf->sg, 1,
                                        DMA_DEV_TO_MEM,
                                        DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
        /*
@@@ -827,12 -827,7 +828,12 @@@ static void pl011_dma_rx_callback(void 
  {
        struct uart_amba_port *uap = data;
        struct pl011_dmarx_data *dmarx = &uap->dmarx;
 +      struct dma_chan *rxchan = dmarx->chan;
        bool lastbuf = dmarx->use_buf_b;
 +      struct pl011_sgbuf *sgbuf = dmarx->use_buf_b ?
 +              &dmarx->sgbuf_b : &dmarx->sgbuf_a;
 +      size_t pending;
 +      struct dma_tx_state state;
        int ret;
  
        /*
         * we immediately trigger the next DMA job.
         */
        spin_lock_irq(&uap->port.lock);
 +      /*
 +       * Rx data can be taken by the UART interrupts during
 +       * the DMA irq handler. So we check the residue here.
 +       */
 +      rxchan->device->device_tx_status(rxchan, dmarx->cookie, &state);
 +      pending = sgbuf->sg.length - state.residue;
 +      BUG_ON(pending > PL011_DMA_BUFFER_SIZE);
 +      /* Then we terminate the transfer - we now know our residue */
 +      dmaengine_terminate_all(rxchan);
 +
        uap->dmarx.running = false;
        dmarx->use_buf_b = !lastbuf;
        ret = pl011_dma_rx_trigger_dma(uap);
  
 -      pl011_dma_rx_chars(uap, PL011_DMA_BUFFER_SIZE, lastbuf, false);
 +      pl011_dma_rx_chars(uap, pending, lastbuf, false);
        spin_unlock_irq(&uap->port.lock);
        /*
         * Do this check after we picked the DMA chars so we don't
@@@ -1396,10 -1381,6 +1397,10 @@@ static int pl011_startup(struct uart_po
  
        uap->port.uartclk = clk_get_rate(uap->clk);
  
 +      /* Clear pending error and receive interrupts */
 +      writew(UART011_OEIS | UART011_BEIS | UART011_PEIS | UART011_FEIS |
 +             UART011_RTIS | UART011_RXIS, uap->port.membase + UART011_ICR);
 +
        /*
         * Allocate the IRQ
         */
        while (readw(uap->port.membase + UART01x_FR) & UART01x_FR_BUSY)
                barrier();
  
 -      cr = UART01x_CR_UARTEN | UART011_CR_RXE | UART011_CR_TXE;
 +      /* restore RTS and DTR */
 +      cr = uap->old_cr & (UART011_CR_RTS | UART011_CR_DTR);
 +      cr |= UART01x_CR_UARTEN | UART011_CR_RXE | UART011_CR_TXE;
        writew(cr, uap->port.membase + UART011_CR);
  
 -      /* Clear pending error interrupts */
 -      writew(UART011_OEIS | UART011_BEIS | UART011_PEIS | UART011_FEIS,
 -             uap->port.membase + UART011_ICR);
 -
        /*
         * initialise the old status of the modem signals
         */
         * as well.
         */
        spin_lock_irq(&uap->port.lock);
 +      /* Clear out any spuriously appearing RX interrupts */
 +       writew(UART011_RTIS | UART011_RXIS,
 +              uap->port.membase + UART011_ICR);
        uap->im = UART011_RTIM;
        if (!pl011_dma_rx_running(uap))
                uap->im |= UART011_RXIM;
@@@ -1490,7 -1470,6 +1491,7 @@@ static void pl011_shutdown_channel(stru
  static void pl011_shutdown(struct uart_port *port)
  {
        struct uart_amba_port *uap = (struct uart_amba_port *)port;
 +      unsigned int cr;
  
        /*
         * disable all interrupts
  
        /*
         * disable the port
 +       * disable the port. It should not disable RTS and DTR.
 +       * Also RTS and DTR state should be preserved to restore
 +       * it during startup().
         */
        uap->autorts = false;
 -      writew(UART01x_CR_UARTEN | UART011_CR_TXE, uap->port.membase + UART011_CR);
 +      cr = readw(uap->port.membase + UART011_CR);
 +      uap->old_cr = cr;
 +      cr &= UART011_CR_RTS | UART011_CR_DTR;
 +      cr |= UART01x_CR_UARTEN | UART011_CR_TXE;
 +      writew(cr, uap->port.membase + UART011_CR);
  
        /*
         * disable break condition and fifos
@@@ -1769,19 -1741,9 +1770,19 @@@ pl011_console_write(struct console *co
  {
        struct uart_amba_port *uap = amba_ports[co->index];
        unsigned int status, old_cr, new_cr;
 +      unsigned long flags;
 +      int locked = 1;
  
        clk_enable(uap->clk);
  
 +      local_irq_save(flags);
 +      if (uap->port.sysrq)
 +              locked = 0;
 +      else if (oops_in_progress)
 +              locked = spin_trylock(&uap->port.lock);
 +      else
 +              spin_lock(&uap->port.lock);
 +
        /*
         *      First save the CR then disable the interrupts
         */
        } while (status & UART01x_FR_BUSY);
        writew(old_cr, uap->port.membase + UART011_CR);
  
 +      if (locked)
 +              spin_unlock(&uap->port.lock);
 +      local_irq_restore(flags);
 +
        clk_disable(uap->clk);
  }
  
@@@ -1945,14 -1903,9 +1946,14 @@@ static int pl011_probe(struct amba_devi
                goto unmap;
        }
  
 +      /* Ensure interrupts from this UART are masked and cleared */
 +      writew(0, uap->port.membase + UART011_IMSC);
 +      writew(0xffff, uap->port.membase + UART011_ICR);
 +
        uap->vendor = vendor;
        uap->lcrh_rx = vendor->lcrh_rx;
        uap->lcrh_tx = vendor->lcrh_tx;
 +      uap->old_cr = 0;
        uap->fifosize = vendor->fifosize;
        uap->interrupt_may_hang = vendor->interrupt_may_hang;
        uap->port.dev = &dev->dev;
index 332f2eb8abbc9552e2779de0692cf6d88b05fa49,61743bdc439bf60e08920631ed4d6d1635815db1..e825460478befc40ad9e9a4d36243fa741a48cf0
@@@ -29,7 -29,6 +29,7 @@@
  #include <linux/nmi.h>
  #include <linux/delay.h>
  
 +#include <linux/debugfs.h>
  #include <linux/dmaengine.h>
  #include <linux/pch_dma.h>
  
@@@ -145,8 -144,6 +145,8 @@@ enum 
  #define PCH_UART_DLL          0x00
  #define PCH_UART_DLM          0x01
  
 +#define PCH_UART_BRCSR                0x0E
 +
  #define PCH_UART_IID_RLS      (PCH_UART_IIR_REI)
  #define PCH_UART_IID_RDR      (PCH_UART_IIR_RRI)
  #define PCH_UART_IID_RDR_TO   (PCH_UART_IIR_RRI | PCH_UART_IIR_TOI)
  
  #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
  
 -#define DEFAULT_BAUD_RATE 1843200 /* 1.8432MHz */
 +#define DEFAULT_UARTCLK   1843200 /*   1.8432 MHz */
 +#define CMITC_UARTCLK   192000000 /* 192.0000 MHz */
 +#define FRI2_64_UARTCLK  64000000 /*  64.0000 MHz */
 +#define FRI2_48_UARTCLK  48000000 /*  48.0000 MHz */
  
  struct pch_uart_buffer {
        unsigned char *buf;
@@@ -224,7 -218,7 +224,7 @@@ struct eg20t_port 
        unsigned int iobase;
        struct pci_dev *pdev;
        int fifo_size;
 -      int base_baud;
 +      int uartclk;
        int start_tx;
        int start_rx;
        int tx_empty;
        int                             tx_dma_use;
        void                            *rx_buf_virt;
        dma_addr_t                      rx_buf_dma;
 +
 +      struct dentry   *debugfs;
  };
  
  /**
@@@ -295,100 -287,26 +295,100 @@@ static struct pch_uart_driver_data drv_
  static struct eg20t_port *pch_uart_ports[PCH_UART_NR];
  #endif
  static unsigned int default_baud = 9600;
 +static unsigned int user_uartclk = 0;
  static const int trigger_level_256[4] = { 1, 64, 128, 224 };
  static const int trigger_level_64[4] = { 1, 16, 32, 56 };
  static const int trigger_level_16[4] = { 1, 4, 8, 14 };
  static const int trigger_level_1[4] = { 1, 1, 1, 1 };
  
 -static void pch_uart_hal_request(struct pci_dev *pdev, int fifosize,
 -                               int base_baud)
 +#ifdef CONFIG_DEBUG_FS
 +
 +#define PCH_REGS_BUFSIZE      1024
 +static int pch_show_regs_open(struct inode *inode, struct file *file)
  {
 -      struct eg20t_port *priv = pci_get_drvdata(pdev);
 +      file->private_data = inode->i_private;
 +      return 0;
 +}
  
 -      priv->trigger_level = 1;
 -      priv->fcr = 0;
 +static ssize_t port_show_regs(struct file *file, char __user *user_buf,
 +                              size_t count, loff_t *ppos)
 +{
 +      struct eg20t_port *priv = file->private_data;
 +      char *buf;
 +      u32 len = 0;
 +      ssize_t ret;
 +      unsigned char lcr;
 +
 +      buf = kzalloc(PCH_REGS_BUFSIZE, GFP_KERNEL);
 +      if (!buf)
 +              return 0;
 +
 +      len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
 +                      "PCH EG20T port[%d] regs:\n", priv->port.line);
 +
 +      len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
 +                      "=================================\n");
 +      len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
 +                      "IER: \t0x%02x\n", ioread8(priv->membase + UART_IER));
 +      len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
 +                      "IIR: \t0x%02x\n", ioread8(priv->membase + UART_IIR));
 +      len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
 +                      "LCR: \t0x%02x\n", ioread8(priv->membase + UART_LCR));
 +      len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
 +                      "MCR: \t0x%02x\n", ioread8(priv->membase + UART_MCR));
 +      len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
 +                      "LSR: \t0x%02x\n", ioread8(priv->membase + UART_LSR));
 +      len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
 +                      "MSR: \t0x%02x\n", ioread8(priv->membase + UART_MSR));
 +      len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
 +                      "BRCSR: \t0x%02x\n",
 +                      ioread8(priv->membase + PCH_UART_BRCSR));
 +
 +      lcr = ioread8(priv->membase + UART_LCR);
 +      iowrite8(PCH_UART_LCR_DLAB, priv->membase + UART_LCR);
 +      len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
 +                      "DLL: \t0x%02x\n", ioread8(priv->membase + UART_DLL));
 +      len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
 +                      "DLM: \t0x%02x\n", ioread8(priv->membase + UART_DLM));
 +      iowrite8(lcr, priv->membase + UART_LCR);
 +
 +      if (len > PCH_REGS_BUFSIZE)
 +              len = PCH_REGS_BUFSIZE;
 +
 +      ret =  simple_read_from_buffer(user_buf, count, ppos, buf, len);
 +      kfree(buf);
 +      return ret;
  }
  
 -static unsigned int get_msr(struct eg20t_port *priv, void __iomem *base)
 +static const struct file_operations port_regs_ops = {
 +      .owner          = THIS_MODULE,
 +      .open           = pch_show_regs_open,
 +      .read           = port_show_regs,
 +      .llseek         = default_llseek,
 +};
 +#endif        /* CONFIG_DEBUG_FS */
 +
 +/* Return UART clock, checking for board specific clocks. */
 +static int pch_uart_get_uartclk(void)
  {
 -      unsigned int msr = ioread8(base + UART_MSR);
 -      priv->dmsr |= msr & PCH_UART_MSR_DELTA;
 +      const char *cmp;
 +
 +      if (user_uartclk)
 +              return user_uartclk;
 +
 +      cmp = dmi_get_system_info(DMI_BOARD_NAME);
 +      if (cmp && strstr(cmp, "CM-iTC"))
 +              return CMITC_UARTCLK;
 +
 +      cmp = dmi_get_system_info(DMI_BIOS_VERSION);
 +      if (cmp && strnstr(cmp, "FRI2", 4))
 +              return FRI2_64_UARTCLK;
 +
 +      cmp = dmi_get_system_info(DMI_PRODUCT_NAME);
 +      if (cmp && strstr(cmp, "Fish River Island II"))
 +              return FRI2_48_UARTCLK;
  
 -      return msr;
 +      return DEFAULT_UARTCLK;
  }
  
  static void pch_uart_hal_enable_interrupt(struct eg20t_port *priv,
@@@ -414,7 -332,7 +414,7 @@@ static int pch_uart_hal_set_line(struc
        unsigned int dll, dlm, lcr;
        int div;
  
 -      div = DIV_ROUND_CLOSEST(priv->base_baud / 16, baud);
 +      div = DIV_ROUND_CLOSEST(priv->uartclk / 16, baud);
        if (div < 0 || USHRT_MAX <= div) {
                dev_err(priv->port.dev, "Invalid Baud(div=0x%x)\n", div);
                return -EINVAL;
@@@ -524,9 -442,8 +524,9 @@@ static int pch_uart_hal_set_fifo(struc
  
  static u8 pch_uart_hal_get_modem(struct eg20t_port *priv)
  {
 -      priv->dmsr = 0;
 -      return get_msr(priv, priv->membase);
 +      unsigned int msr = ioread8(priv->membase + UART_MSR);
 +      priv->dmsr = msr & PCH_UART_MSR_DELTA;
 +      return (u8)msr;
  }
  
  static void pch_uart_hal_write(struct eg20t_port *priv,
@@@ -607,7 -524,7 +607,7 @@@ static int push_rx(struct eg20t_port *p
  
  static int pop_tx_x(struct eg20t_port *priv, unsigned char *buf)
  {
 -      int ret;
 +      int ret = 0;
        struct uart_port *port = &priv->port;
  
        if (port->x_char) {
                buf[0] = port->x_char;
                port->x_char = 0;
                ret = 1;
 -      } else {
 -              ret = 0;
        }
  
        return ret;
@@@ -844,7 -763,7 +844,7 @@@ static int dma_handle_rx(struct eg20t_p
  
        sg_dma_address(sg) = priv->rx_buf_dma;
  
-       desc = priv->chan_rx->device->device_prep_slave_sg(priv->chan_rx,
+       desc = dmaengine_prep_slave_sg(priv->chan_rx,
                        sg, 1, DMA_DEV_TO_MEM,
                        DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  
@@@ -1003,7 -922,7 +1003,7 @@@ static unsigned int dma_handle_tx(struc
                        sg_dma_len(sg) = size;
        }
  
-       desc = priv->chan_tx->device->device_prep_slave_sg(priv->chan_tx,
+       desc = dmaengine_prep_slave_sg(priv->chan_tx,
                                        priv->sg_tx_p, nent, DMA_MEM_TO_DEV,
                                        DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
        if (!desc) {
@@@ -1113,12 -1032,14 +1113,12 @@@ static irqreturn_t pch_uart_interrupt(i
  static unsigned int pch_uart_tx_empty(struct uart_port *port)
  {
        struct eg20t_port *priv;
 -      int ret;
 +
        priv = container_of(port, struct eg20t_port, port);
        if (priv->tx_empty)
 -              ret = TIOCSER_TEMT;
 +              return TIOCSER_TEMT;
        else
 -              ret = 0;
 -
 -      return ret;
 +              return 0;
  }
  
  /* Returns the current state of modem control inputs. */
@@@ -1232,9 -1153,9 +1232,9 @@@ static int pch_uart_startup(struct uart
        priv->tx_empty = 1;
  
        if (port->uartclk)
 -              priv->base_baud = port->uartclk;
 +              priv->uartclk = port->uartclk;
        else
 -              port->uartclk = priv->base_baud;
 +              port->uartclk = priv->uartclk;
  
        pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
        ret = pch_uart_hal_set_line(priv, default_baud,
@@@ -1352,8 -1273,9 +1352,8 @@@ static void pch_uart_set_termios(struc
                else
                        parity = PCH_UART_HAL_PARITY_EVEN;
  
 -      } else {
 +      } else
                parity = PCH_UART_HAL_PARITY_NONE;
 -      }
  
        /* Only UART0 has auto hardware flow function */
        if ((termios->c_cflag & CRTSCTS) && (priv->fifo_size == 256))
@@@ -1525,6 -1447,7 +1525,6 @@@ static voi
  pch_console_write(struct console *co, const char *s, unsigned int count)
  {
        struct eg20t_port *priv;
 -
        unsigned long flags;
        u8 ier;
        int locked = 1;
  static int __init pch_console_setup(struct console *co, char *options)
  {
        struct uart_port *port;
 -      int baud = 9600;
 +      int baud = default_baud;
        int bits = 8;
        int parity = 'n';
        int flow = 'n';
        if (!port || (!port->iobase && !port->membase))
                return -ENODEV;
  
 -      /* setup uartclock */
 -      port->uartclk = DEFAULT_BAUD_RATE;
 +      port->uartclk = pch_uart_get_uartclk();
  
        if (options)
                uart_parse_options(options, &baud, &parity, &bits, &flow);
@@@ -1626,10 -1550,10 +1626,10 @@@ static struct eg20t_port *pch_uart_init
        unsigned int iobase;
        unsigned int mapbase;
        unsigned char *rxbuf;
 -      int fifosize, base_baud;
 +      int fifosize;
        int port_type;
        struct pch_uart_driver_data *board;
 -      const char *board_name;
 +      char name[32];  /* for debugfs file name */
  
        board = &drv_dat[id->driver_data];
        port_type = board->port_type;
        if (!rxbuf)
                goto init_port_free_txbuf;
  
 -      base_baud = DEFAULT_BAUD_RATE;
 -
 -      /* quirk for CM-iTC board */
 -      board_name = dmi_get_system_info(DMI_BOARD_NAME);
 -      if (board_name && strstr(board_name, "CM-iTC"))
 -              base_baud = 192000000; /* 192.0MHz */
 -
        switch (port_type) {
        case PORT_UNKNOWN:
                fifosize = 256; /* EG20T/ML7213: UART0 */
        priv->rxbuf.size = PAGE_SIZE;
  
        priv->fifo_size = fifosize;
 -      priv->base_baud = base_baud;
 +      priv->uartclk = pch_uart_get_uartclk();
        priv->port_type = PORT_MAX_8250 + port_type + 1;
        priv->port.dev = &pdev->dev;
        priv->port.iobase = iobase;
        spin_lock_init(&priv->port.lock);
  
        pci_set_drvdata(pdev, priv);
 -      pch_uart_hal_request(pdev, fifosize, base_baud);
 +      priv->trigger_level = 1;
 +      priv->fcr = 0;
  
  #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
        pch_uart_ports[board->line_no] = priv;
        if (ret < 0)
                goto init_port_hal_free;
  
 +#ifdef CONFIG_DEBUG_FS
 +      snprintf(name, sizeof(name), "uart%d_regs", board->line_no);
 +      priv->debugfs = debugfs_create_file(name, S_IFREG | S_IRUGO,
 +                              NULL, priv, &port_regs_ops);
 +#endif
 +
        return priv;
  
  init_port_hal_free:
@@@ -1715,11 -1639,6 +1715,11 @@@ init_port_alloc_err
  
  static void pch_uart_exit_port(struct eg20t_port *priv)
  {
 +
 +#ifdef CONFIG_DEBUG_FS
 +      if (priv->debugfs)
 +              debugfs_remove(priv->debugfs);
 +#endif
        uart_remove_one_port(&pch_uart_driver, &priv->port);
        pci_set_drvdata(priv->pdev, NULL);
        free_page((unsigned long)priv->rxbuf.buf);
  
  static void pch_uart_pci_remove(struct pci_dev *pdev)
  {
 -      struct eg20t_port *priv;
 -
 -      priv = (struct eg20t_port *)pci_get_drvdata(pdev);
 +      struct eg20t_port *priv = pci_get_drvdata(pdev);
  
        pci_disable_msi(pdev);
  
@@@ -1864,8 -1785,3 +1864,8 @@@ module_exit(pch_uart_module_exit)
  MODULE_LICENSE("GPL v2");
  MODULE_DESCRIPTION("Intel EG20T PCH UART PCI Driver");
  module_param(default_baud, uint, S_IRUGO);
 +MODULE_PARM_DESC(default_baud,
 +                 "Default BAUD for initial driver state and console (default 9600)");
 +module_param(user_uartclk, uint, S_IRUGO);
 +MODULE_PARM_DESC(user_uartclk,
 +                 "Override UART default or board specific UART clock");
index 61b7fd2729cdd5af934766e5ec5b04d154841f25,872557f89cca292addd2ac8861930f937c67f3a6..f8db8a70c14eaaa78f6c9571b346de456c619bc8
@@@ -1338,7 -1338,7 +1338,7 @@@ static void sci_submit_rx(struct sci_po
                struct scatterlist *sg = &s->sg_rx[i];
                struct dma_async_tx_descriptor *desc;
  
-               desc = chan->device->device_prep_slave_sg(chan,
+               desc = dmaengine_prep_slave_sg(chan,
                        sg, 1, DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
  
                if (desc) {
@@@ -1453,7 -1453,7 +1453,7 @@@ static void work_fn_tx(struct work_stru
  
        BUG_ON(!sg_dma_len(sg));
  
-       desc = chan->device->device_prep_slave_sg(chan,
+       desc = dmaengine_prep_slave_sg(chan,
                        sg, s->sg_len_tx, DMA_MEM_TO_DEV,
                        DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
        if (!desc) {
@@@ -1710,8 -1710,6 +1710,8 @@@ static int sci_startup(struct uart_por
  
        dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
  
 +      pm_runtime_put_noidle(port->dev);
 +
        sci_port_enable(s);
  
        ret = sci_request_irq(s);
@@@ -1739,8 -1737,6 +1739,8 @@@ static void sci_shutdown(struct uart_po
        sci_free_irq(s);
  
        sci_port_disable(s);
 +
 +      pm_runtime_get_noresume(port->dev);
  }
  
  static unsigned int sci_scbrr_calc(unsigned int algo_id, unsigned int bps,
@@@ -2079,7 -2075,6 +2079,7 @@@ static int __devinit sci_init_single(st
                sci_init_gpios(sci_port);
  
                pm_runtime_irq_safe(&dev->dev);
 +              pm_runtime_get_noresume(&dev->dev);
                pm_runtime_enable(&dev->dev);
        }
  
index 3648c82a17fe3e20a5682f8fb1d42bcd06898f00,7b4309339f3d652cf04520f247e5f8aa4643be7a..6ec7f838d7faa84383daa73f06a74aeab8d50e56
@@@ -23,7 -23,6 +23,7 @@@
  #define usbhsf_get_cfifo(p)   (&((p)->fifo_info.cfifo))
  #define usbhsf_get_d0fifo(p)  (&((p)->fifo_info.d0fifo))
  #define usbhsf_get_d1fifo(p)  (&((p)->fifo_info.d1fifo))
 +#define usbhsf_is_cfifo(p, f) (usbhsf_get_cfifo(p) == f)
  
  #define usbhsf_fifo_is_busy(f)        ((f)->pipe) /* see usbhs_pipe_select_fifo */
  
@@@ -76,7 -75,8 +76,7 @@@ void usbhs_pkt_push(struct usbhs_pipe *
                pipe->handler = &usbhsf_null_handler;
        }
  
 -      list_del_init(&pkt->node);
 -      list_add_tail(&pkt->node, &pipe->list);
 +      list_move_tail(&pkt->node, &pipe->list);
  
        /*
         * each pkt must hold own handler.
@@@ -106,7 -106,7 +106,7 @@@ static struct usbhs_pkt *__usbhsf_pkt_g
        if (list_empty(&pipe->list))
                return NULL;
  
 -      return list_entry(pipe->list.next, struct usbhs_pkt, node);
 +      return list_first_entry(&pipe->list, struct usbhs_pkt, node);
  }
  
  struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt)
@@@ -305,10 -305,7 +305,10 @@@ static int usbhsf_fifo_select(struct us
        }
  
        /* "base" will be used below  */
 -      usbhs_write(priv, fifo->sel, base | MBW_32);
 +      if (usbhs_get_dparam(priv, has_sudmac) && !usbhsf_is_cfifo(priv, fifo))
 +              usbhs_write(priv, fifo->sel, base);
 +      else
 +              usbhs_write(priv, fifo->sel, base | MBW_32);
  
        /* check ISEL and CURPIPE value */
        while (timeout--) {
@@@ -765,9 -762,9 +765,9 @@@ static int __usbhsf_dma_map_ctrl(struc
  }
  
  static void usbhsf_dma_complete(void *arg);
 -static void usbhsf_dma_prepare_tasklet(unsigned long data)
 +static void xfer_work(struct work_struct *work)
  {
 -      struct usbhs_pkt *pkt = (struct usbhs_pkt *)data;
 +      struct usbhs_pkt *pkt = container_of(work, struct usbhs_pkt, work);
        struct usbhs_pipe *pipe = pkt->pipe;
        struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe);
        struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
        sg_dma_address(&sg) = pkt->dma + pkt->actual;
        sg_dma_len(&sg) = pkt->trans;
  
-       desc = chan->device->device_prep_slave_sg(chan, &sg, 1, dir,
-                                                 DMA_PREP_INTERRUPT |
-                                                 DMA_CTRL_ACK);
+       desc = dmaengine_prep_slave_sg(chan, &sg, 1, dir,
+                                       DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
        if (!desc)
                return;
  
@@@ -847,8 -843,11 +846,8 @@@ static int usbhsf_dma_prepare_push(stru
  
        pkt->trans = len;
  
 -      tasklet_init(&fifo->tasklet,
 -                   usbhsf_dma_prepare_tasklet,
 -                   (unsigned long)pkt);
 -
 -      tasklet_schedule(&fifo->tasklet);
 +      INIT_WORK(&pkt->work, xfer_work);
 +      schedule_work(&pkt->work);
  
        return 0;
  
@@@ -938,8 -937,11 +937,8 @@@ static int usbhsf_dma_try_pop(struct us
  
        pkt->trans = len;
  
 -      tasklet_init(&fifo->tasklet,
 -                   usbhsf_dma_prepare_tasklet,
 -                   (unsigned long)pkt);
 -
 -      tasklet_schedule(&fifo->tasklet);
 +      INIT_WORK(&pkt->work, xfer_work);
 +      schedule_work(&pkt->work);
  
        return 0;
  
index a5966f691ef836954ae1bbee69697c81e98590bd,b3b5b38776f08a9cd315502a45727383a01eac0b..676f967390aeb8ccfe4983a9fab04285d62ce58d
   * The full GNU General Public License is included in this distribution in the
   * file called COPYING.
   */
- #ifndef DMAENGINE_H
- #define DMAENGINE_H
+ #ifndef LINUX_DMAENGINE_H
+ #define LINUX_DMAENGINE_H
  
  #include <linux/device.h>
  #include <linux/uio.h>
 +#include <linux/bug.h>
  #include <linux/scatterlist.h>
  #include <linux/bitmap.h>
+ #include <linux/types.h>
  #include <asm/page.h>
  
  /**
@@@ -258,6 -258,7 +259,7 @@@ struct dma_chan_percpu 
   * struct dma_chan - devices supply DMA channels, clients use them
   * @device: ptr to the dma device who supplies this channel, always !%NULL
   * @cookie: last cookie value returned to client
+  * @completed_cookie: last completed cookie for this channel
   * @chan_id: channel ID for sysfs
   * @dev: class device for sysfs
   * @device_node: used to add this to the device chan list
  struct dma_chan {
        struct dma_device *device;
        dma_cookie_t cookie;
+       dma_cookie_t completed_cookie;
  
        /* sysfs */
        int chan_id;
@@@ -332,6 -334,9 +335,9 @@@ enum dma_slave_buswidth 
   * may or may not be applicable on memory sources.
   * @dst_maxburst: same as src_maxburst but for destination target
   * mutatis mutandis.
+  * @device_fc: Flow Controller Settings. Only valid for slave channels. Fill
+  * with 'true' if peripheral should be flow controller. Direction will be
+  * selected at Runtime.
   *
   * This struct is passed in as configuration data to a DMA engine
   * in order to set up a certain channel for DMA transport at runtime.
@@@ -358,6 -363,7 +364,7 @@@ struct dma_slave_config 
        enum dma_slave_buswidth dst_addr_width;
        u32 src_maxburst;
        u32 dst_maxburst;
+       bool device_fc;
  };
  
  static inline const char *dma_chan_name(struct dma_chan *chan)
@@@ -576,10 -582,11 +583,11 @@@ struct dma_device 
        struct dma_async_tx_descriptor *(*device_prep_slave_sg)(
                struct dma_chan *chan, struct scatterlist *sgl,
                unsigned int sg_len, enum dma_transfer_direction direction,
-               unsigned long flags);
+               unsigned long flags, void *context);
        struct dma_async_tx_descriptor *(*device_prep_dma_cyclic)(
                struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
-               size_t period_len, enum dma_transfer_direction direction);
+               size_t period_len, enum dma_transfer_direction direction,
+               void *context);
        struct dma_async_tx_descriptor *(*device_prep_interleaved_dma)(
                struct dma_chan *chan, struct dma_interleaved_template *xt,
                unsigned long flags);
@@@ -613,7 -620,24 +621,24 @@@ static inline struct dma_async_tx_descr
        struct scatterlist sg;
        sg_init_one(&sg, buf, len);
  
-       return chan->device->device_prep_slave_sg(chan, &sg, 1, dir, flags);
+       return chan->device->device_prep_slave_sg(chan, &sg, 1,
+                                                 dir, flags, NULL);
+ }
+ static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_sg(
+       struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len,
+       enum dma_transfer_direction dir, unsigned long flags)
+ {
+       return chan->device->device_prep_slave_sg(chan, sgl, sg_len,
+                                                 dir, flags, NULL);
+ }
+ static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic(
+               struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
+               size_t period_len, enum dma_transfer_direction dir)
+ {
+       return chan->device->device_prep_dma_cyclic(chan, buf_addr, buf_len,
+                                               period_len, dir, NULL);
  }
  
  static inline int dmaengine_terminate_all(struct dma_chan *chan)
index e43c8fa2788b34062b5601066b112c6c667e5c67,af46b4e2b43845f38442c87c2d0529cb927b9b3e..6b818de2fc03344e6c532067b252655b32c99819
  #include <linux/platform_device.h>
  #include <linux/slab.h>
  #include <linux/dmaengine.h>
+ #include <linux/types.h>
  
  #include <sound/core.h>
  #include <sound/initval.h>
  #include <sound/pcm.h>
  #include <sound/pcm_params.h>
  #include <sound/soc.h>
 +#include <sound/dmaengine_pcm.h>
  
  #include <mach/dma.h>
  
 -#include "imx-ssi.h"
 -
 -struct imx_pcm_runtime_data {
 -      int period_bytes;
 -      int periods;
 -      int dma;
 -      unsigned long offset;
 -      unsigned long size;
 -      void *buf;
 -      int period_time;
 -      struct dma_async_tx_descriptor *desc;
 -      struct dma_chan *dma_chan;
 -      struct imx_dma_data dma_data;
 -};
 -
 -static void audio_dma_irq(void *data)
 -{
 -      struct snd_pcm_substream *substream = (struct snd_pcm_substream *)data;
 -      struct snd_pcm_runtime *runtime = substream->runtime;
 -      struct imx_pcm_runtime_data *iprtd = runtime->private_data;
 -
 -      iprtd->offset += iprtd->period_bytes;
 -      iprtd->offset %= iprtd->period_bytes * iprtd->periods;
 -
 -      snd_pcm_period_elapsed(substream);
 -}
 +#include "imx-pcm.h"
  
  static bool filter(struct dma_chan *chan, void *param)
  {
 -      struct imx_pcm_runtime_data *iprtd = param;
 -
        if (!imx_dma_is_general_purpose(chan))
                return false;
  
 -        chan->private = &iprtd->dma_data;
 +      chan->private = param;
  
 -        return true;
 +      return true;
  }
  
 -static int imx_ssi_dma_alloc(struct snd_pcm_substream *substream,
 +static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream,
                                struct snd_pcm_hw_params *params)
  {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
 +      struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream);
        struct imx_pcm_dma_params *dma_params;
 -      struct snd_pcm_runtime *runtime = substream->runtime;
 -      struct imx_pcm_runtime_data *iprtd = runtime->private_data;
        struct dma_slave_config slave_config;
 -      dma_cap_mask_t mask;
 -      enum dma_slave_buswidth buswidth;
        int ret;
  
        dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
  
 -      iprtd->dma_data.peripheral_type = IMX_DMATYPE_SSI;
 -      iprtd->dma_data.priority = DMA_PRIO_HIGH;
 -      iprtd->dma_data.dma_request = dma_params->dma;
 -
 -      /* Try to grab a DMA channel */
 -      if (!iprtd->dma_chan) {
 -              dma_cap_zero(mask);
 -              dma_cap_set(DMA_SLAVE, mask);
 -              iprtd->dma_chan = dma_request_channel(mask, filter, iprtd);
 -              if (!iprtd->dma_chan)
 -                      return -EINVAL;
 -      }
 -
 -      switch (params_format(params)) {
 -      case SNDRV_PCM_FORMAT_S16_LE:
 -              buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
 -              break;
 -      case SNDRV_PCM_FORMAT_S20_3LE:
 -      case SNDRV_PCM_FORMAT_S24_LE:
 -              buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
 -              break;
 -      default:
 -              return 0;
 -      }
 +      ret = snd_hwparams_to_dma_slave_config(substream, params, &slave_config);
 +      if (ret)
 +              return ret;
  
+       slave_config.device_fc = false;
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
 -              slave_config.direction = DMA_MEM_TO_DEV;
                slave_config.dst_addr = dma_params->dma_addr;
 -              slave_config.dst_addr_width = buswidth;
                slave_config.dst_maxburst = dma_params->burstsize;
        } else {
 -              slave_config.direction = DMA_DEV_TO_MEM;
                slave_config.src_addr = dma_params->dma_addr;
 -              slave_config.src_addr_width = buswidth;
                slave_config.src_maxburst = dma_params->burstsize;
        }
  
 -      ret = dmaengine_slave_config(iprtd->dma_chan, &slave_config);
 +      ret = dmaengine_slave_config(chan, &slave_config);
        if (ret)
                return ret;
  
 -      return 0;
 -}
 -
 -static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream,
 -                              struct snd_pcm_hw_params *params)
 -{
 -      struct snd_soc_pcm_runtime *rtd = substream->private_data;
 -      struct snd_pcm_runtime *runtime = substream->runtime;
 -      struct imx_pcm_runtime_data *iprtd = runtime->private_data;
 -      unsigned long dma_addr;
 -      struct dma_chan *chan;
 -      struct imx_pcm_dma_params *dma_params;
 -      int ret;
 -
 -      dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
 -      ret = imx_ssi_dma_alloc(substream, params);
 -      if (ret)
 -              return ret;
 -      chan = iprtd->dma_chan;
 -
 -      iprtd->size = params_buffer_bytes(params);
 -      iprtd->periods = params_periods(params);
 -      iprtd->period_bytes = params_period_bytes(params);
 -      iprtd->offset = 0;
 -      iprtd->period_time = HZ / (params_rate(params) /
 -                      params_period_size(params));
 -
        snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
  
 -      dma_addr = runtime->dma_addr;
 -
 -      iprtd->buf = (unsigned int *)substream->dma_buffer.area;
 -
 -      iprtd->desc = dmaengine_prep_dma_cyclic(chan, dma_addr,
 -                      iprtd->period_bytes * iprtd->periods,
 -                      iprtd->period_bytes,
 -                      substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
 -                      DMA_MEM_TO_DEV : DMA_DEV_TO_MEM);
 -      if (!iprtd->desc) {
 -              dev_err(&chan->dev->device, "cannot prepare slave dma\n");
 -              return -EINVAL;
 -      }
 -
 -      iprtd->desc->callback = audio_dma_irq;
 -      iprtd->desc->callback_param = substream;
 -
 -      return 0;
 -}
 -
 -static int snd_imx_pcm_hw_free(struct snd_pcm_substream *substream)
 -{
 -      struct snd_pcm_runtime *runtime = substream->runtime;
 -      struct imx_pcm_runtime_data *iprtd = runtime->private_data;
 -
 -      if (iprtd->dma_chan) {
 -              dma_release_channel(iprtd->dma_chan);
 -              iprtd->dma_chan = NULL;
 -      }
 -
 -      return 0;
 -}
 -
 -static int snd_imx_pcm_prepare(struct snd_pcm_substream *substream)
 -{
 -      struct snd_soc_pcm_runtime *rtd = substream->private_data;
 -      struct imx_pcm_dma_params *dma_params;
 -
 -      dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
 -
        return 0;
  }
  
 -static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 -{
 -      struct snd_pcm_runtime *runtime = substream->runtime;
 -      struct imx_pcm_runtime_data *iprtd = runtime->private_data;
 -
 -      switch (cmd) {
 -      case SNDRV_PCM_TRIGGER_START:
 -      case SNDRV_PCM_TRIGGER_RESUME:
 -      case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
 -              dmaengine_submit(iprtd->desc);
 -              dma_async_issue_pending(iprtd->dma_chan);
 -
 -              break;
 -
 -      case SNDRV_PCM_TRIGGER_STOP:
 -      case SNDRV_PCM_TRIGGER_SUSPEND:
 -      case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
 -              dmaengine_terminate_all(iprtd->dma_chan);
 -
 -              break;
 -      default:
 -              return -EINVAL;
 -      }
 -
 -      return 0;
 -}
 -
 -static snd_pcm_uframes_t snd_imx_pcm_pointer(struct snd_pcm_substream *substream)
 -{
 -      struct snd_pcm_runtime *runtime = substream->runtime;
 -      struct imx_pcm_runtime_data *iprtd = runtime->private_data;
 -
 -      pr_debug("%s: %ld %ld\n", __func__, iprtd->offset,
 -                      bytes_to_frames(substream->runtime, iprtd->offset));
 -
 -      return bytes_to_frames(substream->runtime, iprtd->offset);
 -}
 -
  static struct snd_pcm_hardware snd_imx_hardware = {
        .info = SNDRV_PCM_INFO_INTERLEAVED |
                SNDRV_PCM_INFO_BLOCK_TRANSFER |
  
  static int snd_imx_open(struct snd_pcm_substream *substream)
  {
 -      struct snd_pcm_runtime *runtime = substream->runtime;
 -      struct imx_pcm_runtime_data *iprtd;
 +      struct snd_soc_pcm_runtime *rtd = substream->private_data;
 +      struct imx_pcm_dma_params *dma_params;
 +      struct imx_dma_data *dma_data;
        int ret;
  
 -      iprtd = kzalloc(sizeof(*iprtd), GFP_KERNEL);
 -      if (iprtd == NULL)
 -              return -ENOMEM;
 -      runtime->private_data = iprtd;
 +      snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware);
  
 -      ret = snd_pcm_hw_constraint_integer(substream->runtime,
 -                      SNDRV_PCM_HW_PARAM_PERIODS);
 -      if (ret < 0) {
 -              kfree(iprtd);
 -              return ret;
 +      dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
 +
 +      dma_data = kzalloc(sizeof(*dma_data), GFP_KERNEL);
 +      dma_data->peripheral_type = IMX_DMATYPE_SSI;
 +      dma_data->priority = DMA_PRIO_HIGH;
 +      dma_data->dma_request = dma_params->dma;
 +
 +      ret = snd_dmaengine_pcm_open(substream, filter, dma_data);
 +      if (ret) {
 +              kfree(dma_data);
 +              return 0;
        }
  
 -      snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware);
 +      snd_dmaengine_pcm_set_data(substream, dma_data);
  
        return 0;
  }
  
  static int snd_imx_close(struct snd_pcm_substream *substream)
  {
 -      struct snd_pcm_runtime *runtime = substream->runtime;
 -      struct imx_pcm_runtime_data *iprtd = runtime->private_data;
 +      struct imx_dma_data *dma_data = snd_dmaengine_pcm_get_data(substream);
  
 -      kfree(iprtd);
 +      snd_dmaengine_pcm_close(substream);
 +      kfree(dma_data);
  
        return 0;
  }
@@@ -136,8 -294,10 +139,8 @@@ static struct snd_pcm_ops imx_pcm_ops 
        .close          = snd_imx_close,
        .ioctl          = snd_pcm_lib_ioctl,
        .hw_params      = snd_imx_pcm_hw_params,
 -      .hw_free        = snd_imx_pcm_hw_free,
 -      .prepare        = snd_imx_pcm_prepare,
 -      .trigger        = snd_imx_pcm_trigger,
 -      .pointer        = snd_imx_pcm_pointer,
 +      .trigger        = snd_dmaengine_pcm_trigger,
 +      .pointer        = snd_dmaengine_pcm_pointer,
        .mmap           = snd_imx_pcm_mmap,
  };
  
@@@ -149,6 -309,11 +152,6 @@@ static struct snd_soc_platform_driver i
  
  static int __devinit imx_soc_platform_probe(struct platform_device *pdev)
  {
 -      struct imx_ssi *ssi = platform_get_drvdata(pdev);
 -
 -      ssi->dma_params_tx.burstsize = 6;
 -      ssi->dma_params_rx.burstsize = 4;
 -
        return snd_soc_register_platform(&pdev->dev, &imx_soc_platform_mx2);
  }