Commit 5e5a21cf authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: das1800: tidy up das1800_ai_transfer_size()

For aesthetics, pass the fill time 'ns' as a parameter to this function.

Refactor this function to calculate the transfer size in 'samples' instead
of 'bytes'. This removes the need to constantly multiply the values by the
'sample_size'. It also helps avoid any possible integer overflow issues.

Use the comedi_nsamples_left() helper to limit the samples when cmd->stop_src
is TRIG_COUNT.

Use comedi_samples_to_bytes() to return the final DMA size in bytes.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 620ec185
...@@ -967,42 +967,35 @@ static void das1800_setup_counters(struct comedi_device *dev, ...@@ -967,42 +967,35 @@ static void das1800_setup_counters(struct comedi_device *dev,
} }
static unsigned int das1800_ai_transfer_size(struct comedi_device *dev, static unsigned int das1800_ai_transfer_size(struct comedi_device *dev,
struct comedi_subdevice *s) struct comedi_subdevice *s,
unsigned int ns)
{ {
struct comedi_cmd *cmd = &s->async->cmd; struct comedi_cmd *cmd = &s->async->cmd;
unsigned int size = DMA_BUF_SIZE; unsigned int max_samples = comedi_bytes_to_samples(s, DMA_BUF_SIZE);
unsigned int sample_size = comedi_bytes_per_sample(s); unsigned int samples;
unsigned int fill_time = 300000000; /* target time in nanoseconds for filling dma buffer */
unsigned int max_size; /* maximum size we will allow for a transfer */ samples = max_samples;
/* make dma buffer fill in 0.3 seconds for timed modes */ /* for timed modes, make dma buffer fill in 'ns' time */
switch (cmd->scan_begin_src) { switch (cmd->scan_begin_src) {
case TRIG_FOLLOW: /* not in burst mode */ case TRIG_FOLLOW: /* not in burst mode */
if (cmd->convert_src == TRIG_TIMER) if (cmd->convert_src == TRIG_TIMER)
size = (fill_time / cmd->convert_arg) * sample_size; samples = ns / cmd->convert_arg;
break; break;
case TRIG_TIMER: case TRIG_TIMER:
size = (fill_time / (cmd->scan_begin_arg * cmd->chanlist_len)) * samples = ns / (cmd->scan_begin_arg * cmd->chanlist_len);
sample_size;
break;
default:
size = DMA_BUF_SIZE;
break; break;
} }
/* set a minimum and maximum size allowed */ /* limit samples to what is remaining in the command */
max_size = DMA_BUF_SIZE; samples = comedi_nsamples_left(s, samples);
/* if we are taking limited number of conversions, limit transfer size to that */
if (cmd->stop_src == TRIG_COUNT &&
cmd->stop_arg * cmd->chanlist_len * sample_size < max_size)
max_size = cmd->stop_arg * cmd->chanlist_len * sample_size;
if (size > max_size) if (samples > max_samples)
size = max_size; samples = max_samples;
if (size < sample_size) if (samples < 1)
size = sample_size; samples = 1;
return size; return comedi_samples_to_bytes(s, samples);
} }
static void das1800_ai_setup_dma(struct comedi_device *dev, static void das1800_ai_setup_dma(struct comedi_device *dev,
...@@ -1017,8 +1010,8 @@ static void das1800_ai_setup_dma(struct comedi_device *dev, ...@@ -1017,8 +1010,8 @@ static void das1800_ai_setup_dma(struct comedi_device *dev,
devpriv->cur_dma = 0; devpriv->cur_dma = 0;
/* determine a reasonable dma transfer size */ /* determine a dma transfer size to fill buffer in 0.3 sec */
bytes = das1800_ai_transfer_size(dev, s); bytes = das1800_ai_transfer_size(dev, s, 300000000);
dma->size = bytes; dma->size = bytes;
das1800_isadma_program(dma); das1800_isadma_program(dma);
......
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