Commit 88dd0c0a authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: ni_labpc: migrate DMA transfer set-up

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: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 50787fa9
...@@ -387,32 +387,6 @@ static int labpc_ai_insn_read(struct comedi_device *dev, ...@@ -387,32 +387,6 @@ static int labpc_ai_insn_read(struct comedi_device *dev,
return insn->n; 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, static bool labpc_use_continuous_mode(const struct comedi_cmd *cmd,
enum scan_mode mode) enum scan_mode mode)
{ {
...@@ -883,31 +857,8 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -883,31 +857,8 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
labpc_clear_adc_fifo(dev); labpc_clear_adc_fifo(dev);
#ifdef CONFIG_ISA_DMA_API if (xfer == isa_dma_transfer)
/* set up dma transfer */ labpc_setup_dma(dev, s);
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
/* enable error interrupts */ /* enable error interrupts */
devpriv->cmd3 |= CMD3_ERRINTEN; devpriv->cmd3 |= CMD3_ERRINTEN;
......
...@@ -29,6 +29,57 @@ ...@@ -29,6 +29,57 @@
/* size in bytes of dma buffer */ /* size in bytes of dma buffer */
static const int dma_buffer_size = 0xff00; 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) int labpc_init_dma_chan(struct comedi_device *dev, unsigned int dma_chan)
{ {
......
...@@ -18,6 +18,7 @@ static inline bool labpc_have_dma_chan(struct comedi_device *dev) ...@@ -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); int labpc_init_dma_chan(struct comedi_device *dev, unsigned int dma_chan);
void labpc_free_dma_chan(struct comedi_device *dev); void labpc_free_dma_chan(struct comedi_device *dev);
void labpc_setup_dma(struct comedi_device *dev, struct comedi_subdevice *s);
#else #else
...@@ -36,6 +37,11 @@ static inline void labpc_free_dma_chan(struct comedi_device *dev) ...@@ -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
#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