[PATCH 09/15] staging: comedi: ni_labpc_isadma: use comedi_isdma module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/Kconfig                   |  1 +
 drivers/staging/comedi/drivers/ni_labpc.h        | 11 +--
 drivers/staging/comedi/drivers/ni_labpc_common.c |  2 +-
 drivers/staging/comedi/drivers/ni_labpc_isadma.c | 90 +++++++-----------------
 drivers/staging/comedi/drivers/ni_labpc_isadma.h | 16 +----
 5 files changed, 31 insertions(+), 89 deletions(-)

diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig
index 8cbebac..593fcb1 100644
--- a/drivers/staging/comedi/Kconfig
+++ b/drivers/staging/comedi/Kconfig
@@ -1271,6 +1271,7 @@ config COMEDI_NI_LABPC
 
 config COMEDI_NI_LABPC_ISADMA
 	tristate
+	select COMEDI_ISADMA
 
 config COMEDI_NI_TIO
 	tristate
diff --git a/drivers/staging/comedi/drivers/ni_labpc.h b/drivers/staging/comedi/drivers/ni_labpc.h
index c26d7ee..be89ae4 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -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;
 	/*
diff --git a/drivers/staging/comedi/drivers/ni_labpc_common.c b/drivers/staging/comedi/drivers/ni_labpc_common.c
index d89d585..eea7f94 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_common.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_common.c
@@ -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)
diff --git a/drivers/staging/comedi/drivers/ni_labpc_isadma.c b/drivers/staging/comedi/drivers/ni_labpc_isadma.c
index 3100549..6b4ccd8 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_isadma.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_isadma.c
@@ -19,10 +19,10 @@
 
 #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"
@@ -31,35 +31,10 @@
 /* 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);
 
diff --git a/drivers/staging/comedi/drivers/ni_labpc_isadma.h b/drivers/staging/comedi/drivers/ni_labpc_isadma.h
index 8f062f7..b8a1b0e 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_isadma.h
+++ b/drivers/staging/comedi/drivers/ni_labpc_isadma.h
@@ -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)
 {
-- 
2.0.3

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux