]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/dma/apbh_dma.c
merged tx6dl-devel into denx master branch
[karo-tx-uboot.git] / drivers / dma / apbh_dma.c
index 96d4c9bb19960c943fa0666768e30212d996f139..ef7441ce2e3be4eae1f0e4cb7d717fe8969de604 100644 (file)
@@ -23,6 +23,7 @@
 #include <asm/imx-common/regs-apbh.h>
 
 static struct mxs_dma_chan mxs_dma_channels[MXS_MAX_DMA_CHANNELS];
 #include <asm/imx-common/regs-apbh.h>
 
 static struct mxs_dma_chan mxs_dma_channels[MXS_MAX_DMA_CHANNELS];
+static struct mxs_apbh_regs *apbh_regs = (struct mxs_apbh_regs *)MXS_APBH_BASE;
 
 /*
  * Test is the DMA channel is valid channel
 
 /*
  * Test is the DMA channel is valid channel
@@ -31,12 +32,16 @@ int mxs_dma_validate_chan(int channel)
 {
        struct mxs_dma_chan *pchan;
 
 {
        struct mxs_dma_chan *pchan;
 
-       if ((channel < 0) || (channel >= MXS_MAX_DMA_CHANNELS))
+       if ((channel < 0) || (channel >= MXS_MAX_DMA_CHANNELS)) {
+               printf("Invalid DMA channel %d\n", channel);
                return -EINVAL;
                return -EINVAL;
+       }
 
        pchan = mxs_dma_channels + channel;
 
        pchan = mxs_dma_channels + channel;
-       if (!(pchan->flags & MXS_DMA_FLAGS_ALLOCATED))
+       if (!(pchan->flags & MXS_DMA_FLAGS_ALLOCATED)) {
+               printf("DMA channel %d not allocated\n", channel);
                return -EINVAL;
                return -EINVAL;
+       }
 
        return 0;
 }
 
        return 0;
 }
@@ -65,8 +70,6 @@ static unsigned int mxs_dma_cmd_address(struct mxs_dma_desc *desc)
  */
 static int mxs_dma_read_semaphore(int channel)
 {
  */
 static int mxs_dma_read_semaphore(int channel)
 {
-       struct mxs_apbh_regs *apbh_regs =
-               (struct mxs_apbh_regs *)MXS_APBH_BASE;
        uint32_t tmp;
        int ret;
 
        uint32_t tmp;
        int ret;
 
@@ -108,8 +111,6 @@ inline void mxs_dma_flush_desc(struct mxs_dma_desc *desc) {}
  */
 static int mxs_dma_enable(int channel)
 {
  */
 static int mxs_dma_enable(int channel)
 {
-       struct mxs_apbh_regs *apbh_regs =
-               (struct mxs_apbh_regs *)MXS_APBH_BASE;
        unsigned int sem;
        struct mxs_dma_chan *pchan;
        struct mxs_dma_desc *pdesc;
        unsigned int sem;
        struct mxs_dma_chan *pchan;
        struct mxs_dma_desc *pdesc;
@@ -128,7 +129,7 @@ static int mxs_dma_enable(int channel)
 
        pdesc = list_first_entry(&pchan->active, struct mxs_dma_desc, node);
        if (pdesc == NULL)
 
        pdesc = list_first_entry(&pchan->active, struct mxs_dma_desc, node);
        if (pdesc == NULL)
-               return -EFAULT;
+               return -EINVAL;
 
        if (pchan->flags & MXS_DMA_FLAGS_BUSY) {
                if (!(pdesc->cmd.data & MXS_DMA_DESC_CHAIN))
 
        if (pchan->flags & MXS_DMA_FLAGS_BUSY) {
                if (!(pdesc->cmd.data & MXS_DMA_DESC_CHAIN))
@@ -151,12 +152,12 @@ static int mxs_dma_enable(int channel)
        } else {
                pchan->active_num += pchan->pending_num;
                pchan->pending_num = 0;
        } else {
                pchan->active_num += pchan->pending_num;
                pchan->pending_num = 0;
+               writel(1 << (channel + APBH_CTRL0_CLKGATE_CHANNEL_OFFSET),
+                       &apbh_regs->hw_apbh_ctrl0_clr);
                writel(mxs_dma_cmd_address(pdesc),
                        &apbh_regs->ch[channel].hw_apbh_ch_nxtcmdar);
                writel(pchan->active_num,
                        &apbh_regs->ch[channel].hw_apbh_ch_sema);
                writel(mxs_dma_cmd_address(pdesc),
                        &apbh_regs->ch[channel].hw_apbh_ch_nxtcmdar);
                writel(pchan->active_num,
                        &apbh_regs->ch[channel].hw_apbh_ch_sema);
-               writel(1 << (channel + APBH_CTRL0_CLKGATE_CHANNEL_OFFSET),
-                       &apbh_regs->hw_apbh_ctrl0_clr);
        }
 
        pchan->flags |= MXS_DMA_FLAGS_BUSY;
        }
 
        pchan->flags |= MXS_DMA_FLAGS_BUSY;
@@ -180,8 +181,6 @@ static int mxs_dma_enable(int channel)
 static int mxs_dma_disable(int channel)
 {
        struct mxs_dma_chan *pchan;
 static int mxs_dma_disable(int channel)
 {
        struct mxs_dma_chan *pchan;
-       struct mxs_apbh_regs *apbh_regs =
-               (struct mxs_apbh_regs *)MXS_APBH_BASE;
        int ret;
 
        ret = mxs_dma_validate_chan(channel);
        int ret;
 
        ret = mxs_dma_validate_chan(channel);
@@ -190,13 +189,12 @@ static int mxs_dma_disable(int channel)
 
        pchan = mxs_dma_channels + channel;
 
 
        pchan = mxs_dma_channels + channel;
 
-       if (!(pchan->flags & MXS_DMA_FLAGS_BUSY))
+       if ((pchan->flags & MXS_DMA_FLAGS_BUSY)) {
+               printf("%s: DMA channel %d busy\n", __func__, channel);
                return -EINVAL;
                return -EINVAL;
-
+       }
        writel(1 << (channel + APBH_CTRL0_CLKGATE_CHANNEL_OFFSET),
                &apbh_regs->hw_apbh_ctrl0_set);
        writel(1 << (channel + APBH_CTRL0_CLKGATE_CHANNEL_OFFSET),
                &apbh_regs->hw_apbh_ctrl0_set);
-
-       pchan->flags &= ~MXS_DMA_FLAGS_BUSY;
        pchan->active_num = 0;
        pchan->pending_num = 0;
        list_splice_init(&pchan->active, &pchan->done);
        pchan->active_num = 0;
        pchan->pending_num = 0;
        list_splice_init(&pchan->active, &pchan->done);
@@ -209,14 +207,12 @@ static int mxs_dma_disable(int channel)
  */
 static int mxs_dma_reset(int channel)
 {
  */
 static int mxs_dma_reset(int channel)
 {
-       struct mxs_apbh_regs *apbh_regs =
-               (struct mxs_apbh_regs *)MXS_APBH_BASE;
        int ret;
 #if defined(CONFIG_MX23)
        int ret;
 #if defined(CONFIG_MX23)
-       uint32_t setreg = (uint32_t)(&apbh_regs->hw_apbh_ctrl0_set);
+       uint32_t *setreg = &apbh_regs->hw_apbh_ctrl0_set;
        uint32_t offset = APBH_CTRL0_RESET_CHANNEL_OFFSET;
 #elif (defined(CONFIG_MX28) || defined(CONFIG_MX6))
        uint32_t offset = APBH_CTRL0_RESET_CHANNEL_OFFSET;
 #elif (defined(CONFIG_MX28) || defined(CONFIG_MX6))
-       uint32_t setreg = (uint32_t)(&apbh_regs->hw_apbh_channel_ctrl_set);
+       uint32_t *setreg = &apbh_regs->hw_apbh_channel_ctrl_set;
        uint32_t offset = APBH_CHANNEL_CTRL_RESET_CHANNEL_OFFSET;
 #endif
 
        uint32_t offset = APBH_CHANNEL_CTRL_RESET_CHANNEL_OFFSET;
 #endif
 
@@ -236,8 +232,6 @@ static int mxs_dma_reset(int channel)
  */
 static int mxs_dma_enable_irq(int channel, int enable)
 {
  */
 static int mxs_dma_enable_irq(int channel, int enable)
 {
-       struct mxs_apbh_regs *apbh_regs =
-               (struct mxs_apbh_regs *)MXS_APBH_BASE;
        int ret;
 
        ret = mxs_dma_validate_chan(channel);
        int ret;
 
        ret = mxs_dma_validate_chan(channel);
@@ -262,8 +256,6 @@ static int mxs_dma_enable_irq(int channel, int enable)
  */
 static int mxs_dma_ack_irq(int channel)
 {
  */
 static int mxs_dma_ack_irq(int channel)
 {
-       struct mxs_apbh_regs *apbh_regs =
-               (struct mxs_apbh_regs *)MXS_APBH_BASE;
        int ret;
 
        ret = mxs_dma_validate_chan(channel);
        int ret;
 
        ret = mxs_dma_validate_chan(channel);
@@ -499,8 +491,6 @@ static int mxs_dma_finish(int channel, struct list_head *head)
  */
 static int mxs_dma_wait_complete(uint32_t timeout, unsigned int chan)
 {
  */
 static int mxs_dma_wait_complete(uint32_t timeout, unsigned int chan)
 {
-       struct mxs_apbh_regs *apbh_regs =
-               (struct mxs_apbh_regs *)MXS_APBH_BASE;
        int ret;
 
        ret = mxs_dma_validate_chan(chan);
        int ret;
 
        ret = mxs_dma_validate_chan(chan);
@@ -521,7 +511,7 @@ static int mxs_dma_wait_complete(uint32_t timeout, unsigned int chan)
  */
 int mxs_dma_go(int chan)
 {
  */
 int mxs_dma_go(int chan)
 {
-       uint32_t timeout = 10000000;
+       uint32_t timeout = 10000;
        int ret;
 
        LIST_HEAD(tmp_desc_list);
        int ret;
 
        LIST_HEAD(tmp_desc_list);
@@ -549,9 +539,6 @@ int mxs_dma_go(int chan)
  */
 void mxs_dma_init(void)
 {
  */
 void mxs_dma_init(void)
 {
-       struct mxs_apbh_regs *apbh_regs =
-               (struct mxs_apbh_regs *)MXS_APBH_BASE;
-
        mxs_reset_block(&apbh_regs->hw_apbh_ctrl0_reg);
 
 #ifdef CONFIG_APBH_DMA_BURST8
        mxs_reset_block(&apbh_regs->hw_apbh_ctrl0_reg);
 
 #ifdef CONFIG_APBH_DMA_BURST8