Commit 86aff4bb authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: ni_labpc: migrate DMA channel init & free

Migrate the code for requesting an ISA DMA channel and a DMA buffer, and
the code for freeing them into two new functions in the
"ni_labpc_isadma" module: `labpc_init_dma_chan()` and
`labpc_free_dma_chan()`.  Dummy inline functions are provided in
"ni_labpc_isadma.h" if the "ni_labpc_isadma" module is not being built.
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9a638662
...@@ -1708,31 +1708,8 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -1708,31 +1708,8 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
if (ret) if (ret)
return ret; return ret;
#ifdef CONFIG_ISA_DMA_API if (dev->irq)
if (dev->irq && (dma_chan == 1 || dma_chan == 3)) { labpc_init_dma_chan(dev, dma_chan);
void *dma_buffer = kmalloc(dma_buffer_size,
GFP_KERNEL | GFP_DMA);
if (dma_buffer) {
ret = request_dma(dma_chan, dev->board_name);
if (ret == 0) {
unsigned long dma_flags;
devpriv->dma_buffer = dma_buffer;
devpriv->dma_chan = dma_chan;
devpriv->dma_addr =
virt_to_bus(devpriv->dma_buffer);
dma_flags = claim_dma_lock();
disable_dma(devpriv->dma_chan);
set_dma_mode(devpriv->dma_chan, DMA_MODE_READ);
release_dma_lock(dma_flags);
} else {
kfree(dma_buffer);
}
}
}
#endif
return 0; return 0;
} }
...@@ -1741,11 +1718,9 @@ static void labpc_detach(struct comedi_device *dev) ...@@ -1741,11 +1718,9 @@ static void labpc_detach(struct comedi_device *dev)
{ {
struct labpc_private *devpriv = dev->private; struct labpc_private *devpriv = dev->private;
if (devpriv) { if (devpriv)
kfree(devpriv->dma_buffer); labpc_free_dma_chan(dev);
if (devpriv->dma_chan)
free_dma(devpriv->dma_chan);
}
comedi_legacy_detach(dev); comedi_legacy_detach(dev);
} }
......
...@@ -18,9 +18,63 @@ ...@@ -18,9 +18,63 @@
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h>
#include "../comedidev.h"
#include <asm/dma.h>
#include "ni_labpc.h"
#include "ni_labpc_isadma.h" #include "ni_labpc_isadma.h"
/* size in bytes of dma buffer */
static const int dma_buffer_size = 0xff00;
int labpc_init_dma_chan(struct comedi_device *dev, unsigned int dma_chan)
{
struct labpc_private *devpriv = dev->private;
void *dma_buffer;
unsigned long dma_flags;
int ret;
if (dma_chan != 1 && dma_chan != 3)
return -EINVAL;
dma_buffer = kmalloc(dma_buffer_size, GFP_KERNEL | GFP_DMA);
if (!dma_buffer)
return -ENOMEM;
ret = request_dma(dma_chan, dev->board_name);
if (ret) {
kfree(dma_buffer);
return ret;
}
devpriv->dma_buffer = dma_buffer;
devpriv->dma_chan = dma_chan;
devpriv->dma_addr = virt_to_bus(devpriv->dma_buffer);
dma_flags = claim_dma_lock();
disable_dma(devpriv->dma_chan);
set_dma_mode(devpriv->dma_chan, DMA_MODE_READ);
release_dma_lock(dma_flags);
return 0;
}
EXPORT_SYMBOL_GPL(labpc_init_dma_chan);
void labpc_free_dma_chan(struct comedi_device *dev)
{
struct labpc_private *devpriv = dev->private;
kfree(devpriv->dma_buffer);
devpriv->dma_buffer = NULL;
if (devpriv->dma_chan) {
free_dma(devpriv->dma_chan);
devpriv->dma_chan = 0;
}
}
EXPORT_SYMBOL_GPL(labpc_free_dma_chan);
static int __init ni_labpc_isadma_init_module(void) static int __init ni_labpc_isadma_init_module(void)
{ {
return 0; return 0;
......
...@@ -9,8 +9,21 @@ ...@@ -9,8 +9,21 @@
#if NI_LABPC_HAVE_ISA_DMA #if NI_LABPC_HAVE_ISA_DMA
int labpc_init_dma_chan(struct comedi_device *dev, unsigned int dma_chan);
void labpc_free_dma_chan(struct comedi_device *dev);
#else #else
static inline int labpc_init_dma_chan(struct comedi_device *dev,
unsigned int dma_chan)
{
return -ENOTSUPP;
}
static inline void labpc_free_dma_chan(struct comedi_device *dev)
{
}
#endif #endif
#endif /* _NI_LABPC_ISADMA_H */ #endif /* _NI_LABPC_ISADMA_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment