From: Ian Abbott Date: Fri, 28 Jun 2013 16:09:24 +0000 (+0100) Subject: staging: comedi: ni_labpc: migrate DMA transfer set-up X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=88dd0c0a8016d6d80ed47eb306c5b41e8af0f83a;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git 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: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c index dd858d58a93e..e1b073f746fe 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.c +++ b/drivers/staging/comedi/drivers/ni_labpc.c @@ -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; diff --git a/drivers/staging/comedi/drivers/ni_labpc_isadma.c b/drivers/staging/comedi/drivers/ni_labpc_isadma.c index a05297421bd1..dba2be36c48d 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_isadma.c +++ b/drivers/staging/comedi/drivers/ni_labpc_isadma.c @@ -29,6 +29,57 @@ /* 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) { diff --git a/drivers/staging/comedi/drivers/ni_labpc_isadma.h b/drivers/staging/comedi/drivers/ni_labpc_isadma.h index 3b022ea6b564..c721f57daf0c 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_isadma.h +++ b/drivers/staging/comedi/drivers/ni_labpc_isadma.h @@ -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 */