From: H Hartley Sweeten Date: Wed, 5 Nov 2014 17:31:39 +0000 (-0700) Subject: staging: comedi: cb_pcidas64: use comedi_async 'scans_done' to detect AO EOA X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=0be887b92a1d7fce7ea62d09eefacdab9b4370e8;p=linux-beck.git staging: comedi: cb_pcidas64: use comedi_async 'scans_done' to detect AO EOA Remove the private data member 'ao_count' and use the comedi_async 'scans_done' member to detect the analog output end-of-acquisition. Use the comedi_nsamples_left() helper to get the number of samples to actually read from the async buffer. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c index 375bfbb60ebb..05da5b33834a 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas64.c +++ b/drivers/staging/comedi/drivers/cb_pcidas64.c @@ -1085,8 +1085,6 @@ struct pcidas64_private { dma_addr_t ao_dma_desc_bus_addr; /* keeps track of buffer where the next ao sample should go */ unsigned int ao_dma_index; - /* number of analog output samples remaining */ - unsigned long ao_count; unsigned int hw_revision; /* stc chip hardware revision number */ /* last bits sent to INTR_ENABLE_REG register */ unsigned int intr_enable_bits; @@ -2848,22 +2846,6 @@ static int last_ao_dma_load_completed(struct comedi_device *dev) return 1; } -static int ao_stopped_by_error(struct comedi_device *dev, - const struct comedi_cmd *cmd) -{ - struct pcidas64_private *devpriv = dev->private; - - if (cmd->stop_src == TRIG_NONE) - return 1; - if (cmd->stop_src == TRIG_COUNT) { - if (devpriv->ao_count) - return 1; - if (last_ao_dma_load_completed(dev) == 0) - return 1; - } - return 0; -} - static inline int ao_dma_needs_restart(struct comedi_device *dev, unsigned short dma_status) { @@ -2894,20 +2876,13 @@ static unsigned int cb_pcidas64_ao_fill_buffer(struct comedi_device *dev, unsigned short *dest, unsigned int max_bytes) { - struct pcidas64_private *devpriv = dev->private; - struct comedi_cmd *cmd = &s->async->cmd; unsigned int nsamples = comedi_bytes_to_samples(s, max_bytes); unsigned int actual_bytes; - if (cmd->stop_src == TRIG_COUNT && devpriv->ao_count < nsamples) - nsamples = devpriv->ao_count; - + nsamples = comedi_nsamples_left(s, nsamples); actual_bytes = comedi_buf_read_samples(s, dest, nsamples); - nsamples = comedi_bytes_to_samples(s, actual_bytes); - if (cmd->stop_src == TRIG_COUNT) - devpriv->ao_count -= nsamples; - return nsamples; + return comedi_bytes_to_samples(s, actual_bytes); } static unsigned int load_ao_dma_buffer(struct comedi_device *dev, @@ -3006,8 +2981,11 @@ static void handle_ao_interrupt(struct comedi_device *dev, } if ((status & DAC_DONE_BIT)) { - async->events |= COMEDI_CB_EOA; - if (ao_stopped_by_error(dev, cmd)) + if ((cmd->stop_src == TRIG_COUNT && + async->scans_done >= cmd->stop_arg) || + last_ao_dma_load_completed(dev)) + async->events |= COMEDI_CB_EOA; + else async->events |= COMEDI_CB_ERROR; } comedi_handle_events(dev, s); @@ -3202,7 +3180,8 @@ static int prep_ao_dma(struct comedi_device *dev, const struct comedi_cmd *cmd) devpriv->main_iobase + DAC_FIFO_REG); } - if (cmd->stop_src == TRIG_COUNT && devpriv->ao_count == 0) + if (cmd->stop_src == TRIG_COUNT && + s->async->scans_done >= cmd->stop_arg) return 0; nbytes = load_ao_dma_buffer(dev, cmd); @@ -3267,7 +3246,6 @@ static int ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s) writew(0x0, devpriv->main_iobase + DAC_CONTROL0_REG); devpriv->ao_dma_index = 0; - devpriv->ao_count = cmd->stop_arg * cmd->chanlist_len; set_dac_select_reg(dev, cmd); set_dac_interval_regs(dev, cmd);