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

staging: comedi: gsc_hpdi: tidy up gsc_hpdi_drain_dma()

Refactor this function to clarify the loop that reads all the full
buffers.
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 2a5a3d0c
...@@ -210,42 +210,38 @@ struct hpdi_private { ...@@ -210,42 +210,38 @@ struct hpdi_private {
static void gsc_hpdi_drain_dma(struct comedi_device *dev, unsigned int channel) static void gsc_hpdi_drain_dma(struct comedi_device *dev, unsigned int channel)
{ {
struct hpdi_private *devpriv = dev->private; struct hpdi_private *devpriv = dev->private;
struct comedi_async *async = dev->read_subdev->async; struct comedi_subdevice *s = dev->read_subdev;
uint32_t next_transfer_addr; struct comedi_cmd *cmd = &s->async->cmd;
int j; unsigned int idx;
int num_samples = 0; unsigned int start;
void __iomem *pci_addr_reg; unsigned int desc;
unsigned int size;
unsigned int next;
if (channel) if (channel)
pci_addr_reg = next = readl(devpriv->plx9080_iobase + PLX_DMA1_PCI_ADDRESS_REG);
devpriv->plx9080_iobase + PLX_DMA1_PCI_ADDRESS_REG;
else else
pci_addr_reg = next = readl(devpriv->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG);
devpriv->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG;
idx = devpriv->dma_desc_index;
/* loop until we have read all the full buffers */ start = le32_to_cpu(devpriv->dma_desc[idx].pci_start_addr);
j = 0; /* loop until we have read all the full buffers */
for (next_transfer_addr = readl(pci_addr_reg); for (desc = 0; (next < start || next >= start + devpriv->block_size) &&
(next_transfer_addr < desc < devpriv->num_dma_descriptors; desc++) {
le32_to_cpu(devpriv->dma_desc[devpriv->dma_desc_index]. /* transfer data from dma buffer to comedi buffer */
pci_start_addr) size = devpriv->block_size / sizeof(uint32_t);
|| next_transfer_addr >= if (cmd->stop_src == TRIG_COUNT) {
le32_to_cpu(devpriv->dma_desc[devpriv->dma_desc_index]. if (size > devpriv->dio_count)
pci_start_addr) + devpriv->block_size) size = devpriv->dio_count;
&& j < devpriv->num_dma_descriptors; j++) { devpriv->dio_count -= size;
/* transfer data from dma buffer to comedi buffer */
num_samples = devpriv->block_size / sizeof(uint32_t);
if (async->cmd.stop_src == TRIG_COUNT) {
if (num_samples > devpriv->dio_count)
num_samples = devpriv->dio_count;
devpriv->dio_count -= num_samples;
} }
cfc_write_array_to_buffer(dev->read_subdev, cfc_write_array_to_buffer(s, devpriv->desc_dio_buffer[idx],
devpriv->desc_dio_buffer[devpriv-> size * sizeof(uint32_t));
dma_desc_index], idx++;
num_samples * sizeof(uint32_t)); idx %= devpriv->num_dma_descriptors;
devpriv->dma_desc_index++; start = le32_to_cpu(devpriv->dma_desc[idx].pci_start_addr);
devpriv->dma_desc_index %= devpriv->num_dma_descriptors;
devpriv->dma_desc_index = idx;
} }
/* XXX check for buffer overrun somehow */ /* XXX check for buffer overrun somehow */
} }
......
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