staging: comedi: ni_labpc: migrate DMA transfer set-up
authorIan Abbott <abbotti@mev.co.uk>
Fri, 28 Jun 2013 16:09:24 +0000 (17:09 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 23 Jul 2013 21:27:52 +0000 (14:27 -0700)
Migrate the code for setting up an ISA DMA transfer into a new function
`labpc_setup_dma()` in the "ni_labpc_isadma" module.  Provide a dummy
inline function in "ni_labpc_isadma.h" if the "ni_labpc_isadma" module
is not being built.

The static function `labpc_suggest_transfer_size()` also needs to move
across to the new module.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_labpc.c
drivers/staging/comedi/drivers/ni_labpc_isadma.c
drivers/staging/comedi/drivers/ni_labpc_isadma.h

index dd858d58a93eeec7b4622450cbdd9739f53bb976..e1b073f746fe037c3ee57d4b9b7a23d0933fe070 100644 (file)
@@ -387,32 +387,6 @@ static int labpc_ai_insn_read(struct comedi_device *dev,
        return insn->n;
 }
 
-#ifdef CONFIG_ISA_DMA_API
-/* utility function that suggests a dma transfer size in bytes */
-static unsigned int labpc_suggest_transfer_size(const struct comedi_cmd *cmd)
-{
-       unsigned int size;
-       unsigned int freq;
-
-       if (cmd->convert_src == TRIG_TIMER)
-               freq = 1000000000 / cmd->convert_arg;
-       /* return some default value */
-       else
-               freq = 0xffffffff;
-
-       /* make buffer fill in no more than 1/3 second */
-       size = (freq / 3) * sample_size;
-
-       /* set a minimum and maximum size allowed */
-       if (size > dma_buffer_size)
-               size = dma_buffer_size - dma_buffer_size % sample_size;
-       else if (size < sample_size)
-               size = sample_size;
-
-       return size;
-}
-#endif
-
 static bool labpc_use_continuous_mode(const struct comedi_cmd *cmd,
                                      enum scan_mode mode)
 {
@@ -883,31 +857,8 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 
        labpc_clear_adc_fifo(dev);
 
-#ifdef CONFIG_ISA_DMA_API
-       /*  set up dma transfer */
-       if (xfer == isa_dma_transfer) {
-               unsigned long irq_flags;
-
-               irq_flags = claim_dma_lock();
-               disable_dma(devpriv->dma_chan);
-               /* clear flip-flop to make sure 2-byte registers for
-                * count and address get set correctly */
-               clear_dma_ff(devpriv->dma_chan);
-               set_dma_addr(devpriv->dma_chan, devpriv->dma_addr);
-               /*  set appropriate size of transfer */
-               devpriv->dma_transfer_size = labpc_suggest_transfer_size(cmd);
-               if (cmd->stop_src == TRIG_COUNT &&
-                   devpriv->count * sample_size < devpriv->dma_transfer_size) {
-                       devpriv->dma_transfer_size =
-                           devpriv->count * sample_size;
-               }
-               set_dma_count(devpriv->dma_chan, devpriv->dma_transfer_size);
-               enable_dma(devpriv->dma_chan);
-               release_dma_lock(irq_flags);
-               /*  enable board's dma */
-               devpriv->cmd3 |= (CMD3_DMAEN | CMD3_DMATCINTEN);
-       }
-#endif
+       if (xfer == isa_dma_transfer)
+               labpc_setup_dma(dev, s);
 
        /*  enable error interrupts */
        devpriv->cmd3 |= CMD3_ERRINTEN;
index a05297421bd12d042265d2087632dd83a56f6778..dba2be36c48d742b7be453a06987014b9d3e101b 100644 (file)
 
 /* size in bytes of dma buffer */
 static const int dma_buffer_size = 0xff00;
+/* 2 bytes per sample */
+static const int sample_size = 2;
+
+/* utility function that suggests a dma transfer size in bytes */
+static unsigned int labpc_suggest_transfer_size(const struct comedi_cmd *cmd)
+{
+       unsigned int size;
+       unsigned int freq;
+
+       if (cmd->convert_src == TRIG_TIMER)
+               freq = 1000000000 / cmd->convert_arg;
+       else
+               /* return some default value */
+               freq = 0xffffffff;
+
+       /* make buffer fill in no more than 1/3 second */
+       size = (freq / 3) * sample_size;
+
+       /* set a minimum and maximum size allowed */
+       if (size > dma_buffer_size)
+               size = dma_buffer_size - dma_buffer_size % sample_size;
+       else if (size < sample_size)
+               size = sample_size;
+
+       return size;
+}
+
+void labpc_setup_dma(struct comedi_device *dev, struct comedi_subdevice *s)
+{
+       struct labpc_private *devpriv = dev->private;
+       struct comedi_cmd *cmd = &s->async->cmd;
+       unsigned long irq_flags;
+
+       irq_flags = claim_dma_lock();
+       disable_dma(devpriv->dma_chan);
+       /* clear flip-flop to make sure 2-byte registers for
+        * count and address get set correctly */
+       clear_dma_ff(devpriv->dma_chan);
+       set_dma_addr(devpriv->dma_chan, devpriv->dma_addr);
+       /* set appropriate size of transfer */
+       devpriv->dma_transfer_size = labpc_suggest_transfer_size(cmd);
+       if (cmd->stop_src == TRIG_COUNT &&
+           devpriv->count * sample_size < devpriv->dma_transfer_size)
+               devpriv->dma_transfer_size = devpriv->count * sample_size;
+       set_dma_count(devpriv->dma_chan, devpriv->dma_transfer_size);
+       enable_dma(devpriv->dma_chan);
+       release_dma_lock(irq_flags);
+       /* set CMD3 bits for caller to enable DMA and interrupt */
+       devpriv->cmd3 |= (CMD3_DMAEN | CMD3_DMATCINTEN);
+}
+EXPORT_SYMBOL_GPL(labpc_setup_dma);
 
 int labpc_init_dma_chan(struct comedi_device *dev, unsigned int dma_chan)
 {
index 3b022ea6b564c30f015ba9ba1c018c44a2416a77..c721f57daf0c23e58a7b5fa611e69d9a47eb136f 100644 (file)
@@ -18,6 +18,7 @@ static inline bool labpc_have_dma_chan(struct comedi_device *dev)
 
 int labpc_init_dma_chan(struct comedi_device *dev, unsigned int dma_chan);
 void labpc_free_dma_chan(struct comedi_device *dev);
+void labpc_setup_dma(struct comedi_device *dev, struct comedi_subdevice *s);
 
 #else
 
@@ -36,6 +37,11 @@ static inline void labpc_free_dma_chan(struct comedi_device *dev)
 {
 }
 
+static inline void labpc_setup_dma(struct comedi_device *dev,
+                                  struct comedi_subdevice *s)
+{
+}
+
 #endif
 
 #endif /* _NI_LABPC_ISADMA_H */