staging: comedi: ni_labpc_isadma: use comedi_isdma module
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Wed, 14 Jan 2015 17:05:10 +0000 (10:05 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 17 Jan 2015 22:32:55 +0000 (14:32 -0800)
The labpc driver has already had the depends on ISA_DMA_API limitation removed
by moving all the DMA support code into the labpc_isadma module.

For aesthetics, use the comedi_isadma module to provide the actual ISA DMA
support.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/Kconfig
drivers/staging/comedi/drivers/ni_labpc.h
drivers/staging/comedi/drivers/ni_labpc_common.c
drivers/staging/comedi/drivers/ni_labpc_isadma.c
drivers/staging/comedi/drivers/ni_labpc_isadma.h

index 8cbebacb906f08f81dda21d79ecb1a501ebd8c0d..593fcb1783b463ebe08f0cfcc55c15bb17771c74 100644 (file)
@@ -1271,6 +1271,7 @@ config COMEDI_NI_LABPC
 
 config COMEDI_NI_LABPC_ISADMA
        tristate
+       select COMEDI_ISADMA
 
 config COMEDI_NI_TIO
        tristate
index c26d7ee16071a90683acdfedc001bdf992395c3f..be89ae479afcd265ec7b4990a1b8312448320343 100644 (file)
@@ -34,14 +34,9 @@ struct labpc_boardinfo {
        unsigned is_labpc1200:1;        /* has extra regs compared to pc+ */
 };
 
-struct labpc_dma_desc {
-       unsigned int chan;      /* DMA channel */
-       void *virt_addr;        /* virtual address of DMA buffer */
-       dma_addr_t hw_addr;     /* hardware (bus) address of DMA buffer */
-       unsigned int size;      /* size of DMA transfer (in bytes) */
-};
-
 struct labpc_private {
+       struct comedi_isadma *dma;
+
        /*  number of data points left to be taken */
        unsigned long long count;
        /*  software copys of bits written to command registers */
@@ -69,8 +64,6 @@ struct labpc_private {
         */
        unsigned int divisor_b1;
 
-       struct labpc_dma_desc dma_desc;
-
        /* we are using dma/fifo-half-full/etc. */
        enum transfer_type current_transfer;
        /*
index d89d5852aeea5e7440d02a245cc5bad609fb0b30..eea7f940c1f30af0d0ca6e64eb80bddac4ca1602 100644 (file)
@@ -687,7 +687,7 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        }
 
        /* figure out what method we will use to transfer data */
-       if (labpc_have_dma_chan(dev) &&
+       if (devpriv->dma &&
            /* dma unsafe at RT priority,
             * and too much setup time for CMDF_WAKE_EOS */
            (cmd->flags & (CMDF_WAKE_EOS | CMDF_PRIORITY)) == 0)
index 3100549b365c544f6957fa0f93a74118dc596b70..6b4ccd86b3d093b7603bfafafede0264c0bdcadb 100644 (file)
 
 #include <linux/module.h>
 #include <linux/slab.h>
-#include "../comedidev.h"
 
-#include <asm/dma.h>
+#include "../comedidev.h"
 
+#include "comedi_isadma.h"
 #include "comedi_fc.h"
 #include "ni_labpc.h"
 #include "ni_labpc_regs.h"
 /* size in bytes of dma buffer */
 #define LABPC_ISADMA_BUFFER_SIZE       0xff00
 
-static void labpc_isadma_program(struct labpc_dma_desc *dma)
-{
-       unsigned long flags;
-
-       flags = claim_dma_lock();
-       clear_dma_ff(dma->chan);
-       set_dma_mode(dma->chan, DMA_MODE_READ);
-       set_dma_addr(dma->chan, dma->hw_addr);
-       set_dma_count(dma->chan, dma->size);
-       enable_dma(dma->chan);
-       release_dma_lock(flags);
-}
-
-static unsigned int labpc_isadma_disable(struct labpc_dma_desc *dma)
-{
-       unsigned long flags;
-       unsigned int residue;
-
-       flags = claim_dma_lock();
-       disable_dma(dma->chan);
-       residue = get_dma_residue(dma->chan);
-       release_dma_lock(flags);
-
-       return residue;
-}
-
 /* utility function that suggests a dma transfer size in bytes */
 static unsigned int labpc_suggest_transfer_size(struct comedi_device *dev,
-                                               struct comedi_subdevice *s)
+                                               struct comedi_subdevice *s,
+                                               unsigned int maxbytes)
 {
        struct comedi_cmd *cmd = &s->async->cmd;
        unsigned int sample_size = comedi_bytes_per_sample(s);
@@ -76,8 +51,8 @@ static unsigned int labpc_suggest_transfer_size(struct comedi_device *dev,
        size = (freq / 3) * sample_size;
 
        /* set a minimum and maximum size allowed */
-       if (size > LABPC_ISADMA_BUFFER_SIZE)
-               size = LABPC_ISADMA_BUFFER_SIZE;
+       if (size > maxbytes)
+               size = maxbytes;
        else if (size < sample_size)
                size = sample_size;
 
@@ -87,17 +62,17 @@ static unsigned int labpc_suggest_transfer_size(struct comedi_device *dev,
 void labpc_setup_dma(struct comedi_device *dev, struct comedi_subdevice *s)
 {
        struct labpc_private *devpriv = dev->private;
-       struct labpc_dma_desc *dma = &devpriv->dma_desc;
+       struct comedi_isadma_desc *desc = &devpriv->dma->desc[0];
        struct comedi_cmd *cmd = &s->async->cmd;
        unsigned int sample_size = comedi_bytes_per_sample(s);
 
        /* set appropriate size of transfer */
-       dma->size = labpc_suggest_transfer_size(dev, s);
+       desc->size = labpc_suggest_transfer_size(dev, s, desc->maxsize);
        if (cmd->stop_src == TRIG_COUNT &&
-           devpriv->count * sample_size < dma->size)
-               dma->size = devpriv->count * sample_size;
+           devpriv->count * sample_size < desc->size)
+               desc->size = devpriv->count * sample_size;
 
-       labpc_isadma_program(dma);
+       comedi_isadma_program(desc);
 
        /* set CMD3 bits for caller to enable DMA and interrupt */
        devpriv->cmd3 |= (CMD3_DMAEN | CMD3_DMATCINTEN);
@@ -107,11 +82,11 @@ EXPORT_SYMBOL_GPL(labpc_setup_dma);
 void labpc_drain_dma(struct comedi_device *dev)
 {
        struct labpc_private *devpriv = dev->private;
-       struct labpc_dma_desc *dma = &devpriv->dma_desc;
+       struct comedi_isadma_desc *desc = &devpriv->dma->desc[0];
        struct comedi_subdevice *s = dev->read_subdev;
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
-       unsigned int max_samples = comedi_bytes_to_samples(s, dma->size);
+       unsigned int max_samples = comedi_bytes_to_samples(s, desc->size);
        unsigned int residue;
        unsigned int nsamples;
        unsigned int leftover;
@@ -121,7 +96,7 @@ void labpc_drain_dma(struct comedi_device *dev)
         * transfer.  It should always be zero at this point unless
         * the stop_src is set to external triggering.
         */
-       residue = labpc_isadma_disable(dma);
+       residue = comedi_isadma_disable(desc->chan);
 
        /*
         * Figure out how many samples to read for this transfer and
@@ -141,21 +116,21 @@ void labpc_drain_dma(struct comedi_device *dev)
        } else {
                leftover = max_samples;
        }
-       dma->size = comedi_samples_to_bytes(s, leftover);
+       desc->size = comedi_samples_to_bytes(s, leftover);
 
-       comedi_buf_write_samples(s, dma->virt_addr, nsamples);
+       comedi_buf_write_samples(s, desc->virt_addr, nsamples);
 }
 EXPORT_SYMBOL_GPL(labpc_drain_dma);
 
 static void handle_isa_dma(struct comedi_device *dev)
 {
        struct labpc_private *devpriv = dev->private;
-       struct labpc_dma_desc *dma = &devpriv->dma_desc;
+       struct comedi_isadma_desc *desc = &devpriv->dma->desc[0];
 
        labpc_drain_dma(dev);
 
-       if (dma->size)
-               labpc_isadma_program(dma);
+       if (desc->size)
+               comedi_isadma_program(desc);
 
        /* clear dma tc interrupt */
        devpriv->write_byte(dev, 0x1, DMATC_CLEAR_REG);
@@ -179,37 +154,24 @@ EXPORT_SYMBOL_GPL(labpc_handle_dma_status);
 void labpc_init_dma_chan(struct comedi_device *dev, unsigned int dma_chan)
 {
        struct labpc_private *devpriv = dev->private;
-       struct labpc_dma_desc *dma = &devpriv->dma_desc;
 
+       /* only DMA channels 3 and 1 are valid */
        if (dma_chan != 1 && dma_chan != 3)
                return;
 
-       if (request_dma(dma_chan, dev->board_name))
-               return;
-
-       dma->virt_addr = dma_alloc_coherent(NULL, LABPC_ISADMA_BUFFER_SIZE,
-                                           &dma->hw_addr, GFP_KERNEL);
-       if (!dma->virt_addr) {
-               free_dma(dma_chan);
-               return;
-       }
-
-       dma->chan = dma_chan;
-
-       labpc_isadma_disable(dma);
+       /* DMA uses 1 buffer */
+       devpriv->dma = comedi_isadma_alloc(dev, 1, dma_chan, dma_chan,
+                                          LABPC_ISADMA_BUFFER_SIZE,
+                                          COMEDI_ISADMA_READ);
 }
 EXPORT_SYMBOL_GPL(labpc_init_dma_chan);
 
 void labpc_free_dma_chan(struct comedi_device *dev)
 {
        struct labpc_private *devpriv = dev->private;
-       struct labpc_dma_desc *dma = &devpriv->dma_desc;
 
-       if (dma->virt_addr)
-               dma_free_coherent(NULL, LABPC_ISADMA_BUFFER_SIZE,
-                                 dma->virt_addr, dma->hw_addr);
-       if (dma->chan)
-               free_dma(dma->chan);
+       if (devpriv)
+               comedi_isadma_free(devpriv->dma);
 }
 EXPORT_SYMBOL_GPL(labpc_free_dma_chan);
 
index 8f062f70588367d29c31ae19999ffa403ce86a94..b8a1b0ee62902f5f8ce4292f01e24c3125777aee 100644 (file)
@@ -5,16 +5,7 @@
 #ifndef _NI_LABPC_ISADMA_H
 #define _NI_LABPC_ISADMA_H
 
-#define NI_LABPC_HAVE_ISA_DMA  IS_ENABLED(CONFIG_COMEDI_NI_LABPC_ISADMA)
-
-#if NI_LABPC_HAVE_ISA_DMA
-
-static inline bool labpc_have_dma_chan(struct comedi_device *dev)
-{
-       struct labpc_private *devpriv = dev->private;
-
-       return (bool)devpriv->dma_desc.chan;
-}
+#if IS_ENABLED(CONFIG_COMEDI_NI_LABPC_ISADMA)
 
 void labpc_init_dma_chan(struct comedi_device *dev, unsigned int dma_chan);
 void labpc_free_dma_chan(struct comedi_device *dev);
@@ -24,11 +15,6 @@ void labpc_handle_dma_status(struct comedi_device *dev);
 
 #else
 
-static inline bool labpc_have_dma_chan(struct comedi_device *dev)
-{
-       return false;
-}
-
 static inline void labpc_init_dma_chan(struct comedi_device *dev,
                                       unsigned int dma_chan)
 {