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

staging: comedi: dt282x: introduce dt282x_ao_setup_dma()

Introduce a helper function to read the analog output samples from the
async buffer and prep the DMA.

Use comedi_buf_read_samples() to read the analog output samples from
the async buffer.
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 7bd7d905
...@@ -449,13 +449,29 @@ static void dt282x_munge(struct comedi_device *dev, ...@@ -449,13 +449,29 @@ static void dt282x_munge(struct comedi_device *dev,
} }
} }
static unsigned int dt282x_ao_setup_dma(struct comedi_device *dev,
struct comedi_subdevice *s,
int cur_dma)
{
struct dt282x_private *devpriv = dev->private;
void *ptr = devpriv->dma[cur_dma].buf;
unsigned int nsamples = devpriv->dma_maxsize / bytes_per_sample(s);
unsigned int nbytes;
nbytes = comedi_buf_read_samples(s, ptr, nsamples);
if (nbytes)
dt282x_prep_ao_dma(dev, cur_dma, nbytes);
else
dev_err(dev->class_dev, "AO underrun\n");
return nbytes;
}
static void dt282x_ao_dma_interrupt(struct comedi_device *dev, static void dt282x_ao_dma_interrupt(struct comedi_device *dev,
struct comedi_subdevice *s) struct comedi_subdevice *s)
{ {
struct dt282x_private *devpriv = dev->private; struct dt282x_private *devpriv = dev->private;
int cur_dma = devpriv->current_dma_index; int cur_dma = devpriv->current_dma_index;
void *ptr = devpriv->dma[cur_dma].buf;
int size;
outw(devpriv->supcsr | DT2821_SUPCSR_CLRDMADNE, outw(devpriv->supcsr | DT2821_SUPCSR_CLRDMADNE,
dev->iobase + DT2821_SUPCSR_REG); dev->iobase + DT2821_SUPCSR_REG);
...@@ -464,13 +480,8 @@ static void dt282x_ao_dma_interrupt(struct comedi_device *dev, ...@@ -464,13 +480,8 @@ static void dt282x_ao_dma_interrupt(struct comedi_device *dev,
devpriv->current_dma_index = 1 - cur_dma; devpriv->current_dma_index = 1 - cur_dma;
size = cfc_read_array_from_buffer(s, ptr, devpriv->dma_maxsize); if (!dt282x_ao_setup_dma(dev, s, cur_dma))
if (size == 0) {
dev_err(dev->class_dev, "AO underrun\n");
s->async->events |= COMEDI_CB_OVERFLOW; s->async->events |= COMEDI_CB_OVERFLOW;
} else {
dt282x_prep_ao_dma(dev, cur_dma, size);
}
} }
static void dt282x_ai_dma_interrupt(struct comedi_device *dev, static void dt282x_ai_dma_interrupt(struct comedi_device *dev,
...@@ -916,26 +927,15 @@ static int dt282x_ao_inttrig(struct comedi_device *dev, ...@@ -916,26 +927,15 @@ static int dt282x_ao_inttrig(struct comedi_device *dev,
{ {
struct dt282x_private *devpriv = dev->private; struct dt282x_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd; struct comedi_cmd *cmd = &s->async->cmd;
int size;
if (trig_num != cmd->start_src) if (trig_num != cmd->start_src)
return -EINVAL; return -EINVAL;
size = cfc_read_array_from_buffer(s, devpriv->dma[0].buf, if (!dt282x_ao_setup_dma(dev, s, 0))
devpriv->dma_maxsize);
if (size == 0) {
dev_err(dev->class_dev, "AO underrun\n");
return -EPIPE; return -EPIPE;
}
dt282x_prep_ao_dma(dev, 0, size);
size = cfc_read_array_from_buffer(s, devpriv->dma[1].buf, if (!dt282x_ao_setup_dma(dev, s, 1))
devpriv->dma_maxsize);
if (size == 0) {
dev_err(dev->class_dev, "AO underrun\n");
return -EPIPE; return -EPIPE;
}
dt282x_prep_ao_dma(dev, 1, size);
outw(devpriv->supcsr | DT2821_SUPCSR_STRIG, outw(devpriv->supcsr | DT2821_SUPCSR_STRIG,
dev->iobase + DT2821_SUPCSR_REG); dev->iobase + DT2821_SUPCSR_REG);
......
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