sh: G2 DMA IRQ and residue sampling.
authorPaul Mundt <lethal@linux-sh.org>
Wed, 27 Sep 2006 07:53:40 +0000 (16:53 +0900)
committerPaul Mundt <lethal@linux-sh.org>
Wed, 27 Sep 2006 07:53:40 +0000 (16:53 +0900)
This fixes a long-standing FIXME for G2 DMA, where we finally
wire up the IRQ handler and allow for sampling remaining bytes
while in-flight.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
arch/sh/drivers/dma/dma-g2.c

index 0f866f8789f0de6e4338fab51cb40490290ed055..9cb0709241808b6365e1a024f048722cbffb8a94 100644 (file)
@@ -3,7 +3,7 @@
  *
  * G2 bus DMA support
  *
- * Copyright (C) 2003, 2004  Paul Mundt
+ * Copyright (C) 2003 - 2006  Paul Mundt
  *
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
@@ -13,7 +13,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
-
+#include <asm/cacheflush.h>
 #include <asm/mach/sysasic.h>
 #include <asm/mach/dma.h>
 #include <asm/dma.h>
@@ -47,17 +47,31 @@ struct g2_dma_info {
 
 static volatile struct g2_dma_info *g2_dma = (volatile struct g2_dma_info *)0xa05f7800;
 
+#define g2_bytes_remaining(i) \
+       ((g2_dma->channel[i].size - \
+         g2_dma->status[i].size) & 0x0fffffff)
+
 static irqreturn_t g2_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
-       /* FIXME: Do some meaningful completion work here.. */
-       return IRQ_HANDLED;
-}
+       int i;
 
-static struct irqaction g2_dma_irq = {
-       .name           = "g2 DMA handler",
-       .handler        = g2_dma_interrupt,
-       .flags          = IRQF_DISABLED,
-};
+       for (i = 0; i < G2_NR_DMA_CHANNELS; i++) {
+               if (g2_dma->status[i].status & 0x20000000) {
+                       unsigned int bytes = g2_bytes_remaining(i);
+
+                       if (likely(bytes == 0)) {
+                               struct dma_info *info = dev_id;
+                               struct dma_channel *chan = info->channels + i;
+
+                               wake_up(&chan->wait_queue);
+
+                               return IRQ_HANDLED;
+                       }
+               }
+       }
+
+       return IRQ_NONE;
+}
 
 static int g2_enable_dma(struct dma_channel *chan)
 {
@@ -135,8 +149,14 @@ static int g2_xfer_dma(struct dma_channel *chan)
        return 0;
 }
 
+static int g2_get_residue(struct dma_channel *chan)
+{
+       return g2_bytes_remaining(chan->chan);
+}
+
 static struct dma_ops g2_dma_ops = {
        .xfer           = g2_xfer_dma,
+       .get_residue    = g2_get_residue,
 };
 
 static struct dma_info g2_dma_info = {
@@ -148,13 +168,22 @@ static struct dma_info g2_dma_info = {
 
 static int __init g2_dma_init(void)
 {
-       setup_irq(HW_EVENT_G2_DMA, &g2_dma_irq);
+       int ret;
+
+       ret = request_irq(HW_EVENT_G2_DMA, g2_dma_interrupt, IRQF_DISABLED,
+                         "g2 DMA handler", &g2_dma_info);
+       if (unlikely(ret))
+               return -EINVAL;
 
        /* Magic */
        g2_dma->wait_state      = 27;
        g2_dma->magic           = 0x4659404f;
 
-       return register_dmac(&g2_dma_info);
+       ret = register_dmac(&g2_dma_info);
+       if (unlikely(ret != 0))
+               free_irq(HW_EVENT_G2_DMA, 0);
+
+       return ret;
 }
 
 static void __exit g2_dma_exit(void)
@@ -169,4 +198,3 @@ module_exit(g2_dma_exit);
 MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>");
 MODULE_DESCRIPTION("G2 bus DMA driver");
 MODULE_LICENSE("GPL");
-