staging: comedi: gsc_hpdi: tidy up gsc_hpdi_drain_dma()
authorH Hartley Sweeten <hartleys@visionengravers.com>
Thu, 13 Mar 2014 21:16:27 +0000 (14:16 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 17 Mar 2014 21:19:51 +0000 (14:19 -0700)
Refactor this function to clarify the loop that reads all the full
buffers.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/gsc_hpdi.c

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