]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
staging: comedi: das1800: use comedi_async 'scans_done' to detect EOA
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Wed, 5 Nov 2014 17:31:41 +0000 (10:31 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Nov 2014 17:29:42 +0000 (09:29 -0800)
Remove the private data member 'count' and use the comedi_async 'scans_done'
member to detect the end-of-acquisition.

Use the comedi_nsamples_left() helper to get the number of samples to actually
add to the async buffer.

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/das1800.c

index 03b1ff9de92ca5d05ba7c2129cf8af45a2f8df5a..be825d21a185ff12de9ff23294dc88a4fd14f230 100644 (file)
@@ -421,7 +421,6 @@ static const struct das1800_board das1800_boards[] = {
 };
 
 struct das1800_private {
-       unsigned int count;     /* number of data points left to be taken */
        unsigned int divisor1;  /* value to load into board's counter 1 for timed conversions */
        unsigned int divisor2;  /* value to load into board's counter 2 for timed conversions */
        int irq_dma_bits;       /* bits for control register b */
@@ -479,41 +478,33 @@ static void das1800_handle_fifo_half_full(struct comedi_device *dev,
                                          struct comedi_subdevice *s)
 {
        struct das1800_private *devpriv = dev->private;
-       int numPoints = 0;      /* number of points to read */
-       struct comedi_cmd *cmd = &s->async->cmd;
+       unsigned int nsamples = comedi_nsamples_left(s, FIFO_SIZE / 2);
 
-       numPoints = FIFO_SIZE / 2;
-       /* if we only need some of the points */
-       if (cmd->stop_src == TRIG_COUNT && devpriv->count < numPoints)
-               numPoints = devpriv->count;
-       insw(dev->iobase + DAS1800_FIFO, devpriv->ai_buf0, numPoints);
-       munge_data(dev, devpriv->ai_buf0, numPoints);
-       comedi_buf_write_samples(s, devpriv->ai_buf0, numPoints);
-       if (cmd->stop_src == TRIG_COUNT)
-               devpriv->count -= numPoints;
+       insw(dev->iobase + DAS1800_FIFO, devpriv->ai_buf0, nsamples);
+       munge_data(dev, devpriv->ai_buf0, nsamples);
+       comedi_buf_write_samples(s, devpriv->ai_buf0, nsamples);
 }
 
 static void das1800_handle_fifo_not_empty(struct comedi_device *dev,
                                          struct comedi_subdevice *s)
 {
-       struct das1800_private *devpriv = dev->private;
+       struct comedi_cmd *cmd = &s->async->cmd;
        unsigned short dpnt;
        int unipolar;
-       struct comedi_cmd *cmd = &s->async->cmd;
 
        unipolar = inb(dev->iobase + DAS1800_CONTROL_C) & UB;
 
        while (inb(dev->iobase + DAS1800_STATUS) & FNE) {
-               if (cmd->stop_src == TRIG_COUNT && devpriv->count == 0)
-                       break;
                dpnt = inw(dev->iobase + DAS1800_FIFO);
                /* convert to unsigned type if we are in a bipolar mode */
                if (!unipolar)
                        ;
                dpnt = munge_bipolar_sample(dev, dpnt);
                comedi_buf_write_samples(s, &dpnt, 1);
-               if (cmd->stop_src == TRIG_COUNT)
-                       devpriv->count--;
+
+               if (cmd->stop_src == TRIG_COUNT &&
+                   s->async->scans_done >= cmd->stop_arg)
+                       break;
        }
 }
 
@@ -524,8 +515,8 @@ static void das1800_flush_dma_channel(struct comedi_device *dev,
                                      unsigned int channel, uint16_t *buffer)
 {
        struct das1800_private *devpriv = dev->private;
-       unsigned int num_bytes, num_samples;
-       struct comedi_cmd *cmd = &s->async->cmd;
+       unsigned int nbytes;
+       unsigned int nsamples;
 
        disable_dma(channel);
 
@@ -534,17 +525,12 @@ static void das1800_flush_dma_channel(struct comedi_device *dev,
        clear_dma_ff(channel);
 
        /*  figure out how many points to read */
-       num_bytes = devpriv->dma_transfer_size - get_dma_residue(channel);
-       num_samples = comedi_bytes_to_samples(s, num_bytes);
-
-       /* if we only need some of the points */
-       if (cmd->stop_src == TRIG_COUNT && devpriv->count < num_samples)
-               num_samples = devpriv->count;
+       nbytes = devpriv->dma_transfer_size - get_dma_residue(channel);
+       nsamples = comedi_bytes_to_samples(s, nbytes);
+       nsamples = comedi_nsamples_left(s, nsamples);
 
-       munge_data(dev, buffer, num_samples);
-       comedi_buf_write_samples(s, buffer, num_samples);
-       if (cmd->stop_src == TRIG_COUNT)
-               devpriv->count -= num_samples;
+       munge_data(dev, buffer, nsamples);
+       comedi_buf_write_samples(s, buffer, nsamples);
 }
 
 /* flushes remaining data from board when external trigger has stopped acquisition
@@ -668,7 +654,8 @@ static void das1800_ai_handler(struct comedi_device *dev)
                else
                        das1800_handle_fifo_not_empty(dev, s);
                async->events |= COMEDI_CB_EOA;
-       } else if (cmd->stop_src == TRIG_COUNT && devpriv->count == 0) {        /*  stop_src TRIG_COUNT */
+       } else if (cmd->stop_src == TRIG_COUNT &&
+                  async->scans_done >= cmd->stop_arg) {
                async->events |= COMEDI_CB_EOA;
        }
 
@@ -1100,9 +1087,6 @@ static int das1800_ai_do_cmd(struct comedi_device *dev,
                /*  interrupt fifo half full */
                devpriv->irq_dma_bits |= FIMD;
        }
-       /*  determine how many conversions we need */
-       if (cmd->stop_src == TRIG_COUNT)
-               devpriv->count = cmd->stop_arg * cmd->chanlist_len;
 
        das1800_cancel(dev, s);