]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
staging: comedi: drivers: move comedi_async 'cur_chan' tracking into the core
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Fri, 31 Oct 2014 16:49:31 +0000 (09:49 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 4 Nov 2014 00:31:24 +0000 (16:31 -0800)
The commedi_async 'cur_chan' member is used to track the current position
in the chanlist for a scan. Currently only a couple comedi drivers use
this member.

For aeshtetics, move the 'cur_chan' tracking into the core for non-SDF_PACKED
subdevices. The 'cur_chan' will be updated after reading or writing samples
to the async buffer by comedi_inc_scan_progress(). All non-SDF_PACKED subdevices
will then automatiaclly track the 'cur_chan'.

Some of the drivers use the 'cur_chan' to detect the end of scan event when
counting scans. The COMEDI_CB_EOS event is automatically added by the core
when the end of scan is detected. The drivers just need to check if the
'cur_chan' is 0 to count the number of scans completed.

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.c
drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
drivers/staging/comedi/drivers/adl_pci9118.c
drivers/staging/comedi/drivers/adv_pci1710.c
drivers/staging/comedi/drivers/ni_mio_common.c
drivers/staging/comedi/drivers/pcl812.c
drivers/staging/comedi/drivers/pcl816.c
drivers/staging/comedi/drivers/pcl818.c
drivers/staging/comedi/drivers/rtd520.c

index ff2df8587eca2c781605f946527108f08362a55a..9c55dc759af8cddd4bef0057d8115139f3caa963 100644 (file)
@@ -341,8 +341,15 @@ void comedi_inc_scan_progress(struct comedi_subdevice *s,
                              unsigned int num_bytes)
 {
        struct comedi_async *async = s->async;
+       struct comedi_cmd *cmd = &async->cmd;
        unsigned int scan_length = comedi_bytes_per_scan(s);
 
+       /* track the 'cur_chan' for non-SDF_PACKED subdevices */
+       if (!(s->subdev_flags & SDF_PACKED)) {
+               async->cur_chan += comedi_bytes_to_samples(s, num_bytes);
+               async->cur_chan %= cmd->chanlist_len;
+       }
+
        async->scan_progress += num_bytes;
        if (async->scan_progress >= scan_length) {
                async->scan_progress %= scan_length;
index 6b65ce69c213787722c352ea62251a4710db50a2..facd2c4b922d4af5014e30fc13ec433dcd668cf1 100644 (file)
@@ -1167,8 +1167,6 @@ static void v_APCI3120_InterruptDmaMoveBlock16bit(struct comedi_device *dev,
 
        devpriv->ui_AiActualScan +=
                (s->async->cur_chan + num_samples) / cmd->scan_end_arg;
-       s->async->cur_chan += num_samples;
-       s->async->cur_chan %= cmd->scan_end_arg;
 
        comedi_buf_write_samples(s, dma_buffer, num_samples);
 }
index 83c381357c14efb7beb42d448d0f41b10c4718ba..93b41e6712a6cbc369a13111a43d6aa19182ca71 100644 (file)
@@ -483,8 +483,6 @@ static void move_block_from_dma(struct comedi_device *dev,
        num_samples = defragment_dma_buffer(dev, s, dma_buffer, num_samples);
        devpriv->ai_act_scan +=
            (s->async->cur_chan + num_samples) / cmd->scan_end_arg;
-       s->async->cur_chan += num_samples;
-       s->async->cur_chan %= cmd->scan_end_arg;
 
        comedi_buf_write_samples(s, dma_buffer, num_samples);
 }
@@ -612,10 +610,8 @@ static void interrupt_pci9118_ai_onesample(struct comedi_device *dev,
        sampl = inl(dev->iobase + PCI9118_AI_FIFO_REG);
 
        comedi_buf_write_samples(s, &sampl, 1);
-       s->async->cur_chan++;
-       if (s->async->cur_chan >= cmd->scan_end_arg) {
-                                                       /* one scan done */
-               s->async->cur_chan %= cmd->scan_end_arg;
+
+       if (s->async->cur_chan == 0) {
                devpriv->ai_act_scan++;
                if (!devpriv->ai_neverending) {
                        /* all data sampled? */
index 075df1ccb8530b4eb0ccc3e4c75723833e133cd2..420554f79b02e26f09f0cb8c6bf387efa20a42e0 100644 (file)
@@ -772,11 +772,6 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
                val &= s->maxdata;
                comedi_buf_write_samples(s, &val, 1);
 
-               s->async->cur_chan++;
-               if (s->async->cur_chan >= cmd->chanlist_len)
-                       s->async->cur_chan = 0;
-
-
                if (s->async->cur_chan == 0) {  /*  one scan done */
                        devpriv->ai_act_scan++;
                        if (cmd->stop_src == TRIG_COUNT &&
@@ -800,7 +795,6 @@ static int move_block_from_fifo(struct comedi_device *dev,
                                struct comedi_subdevice *s, int n, int turn)
 {
        struct pci1710_private *devpriv = dev->private;
-       struct comedi_cmd *cmd = &s->async->cmd;
        unsigned int val;
        int ret;
        int i;
@@ -817,11 +811,8 @@ static int move_block_from_fifo(struct comedi_device *dev,
                val &= s->maxdata;
                comedi_buf_write_samples(s, &val, 1);
 
-               s->async->cur_chan++;
-               if (s->async->cur_chan >= cmd->chanlist_len) {
-                       s->async->cur_chan = 0;
+               if (s->async->cur_chan == 0)
                        devpriv->ai_act_scan++;
-               }
        }
        return 0;
 }
index 32236ef587f539b0fd20e819de358dee91719dcf..2dfd95126fa38cfe13ab54597df4c5a9c15363db 100644 (file)
@@ -1125,14 +1125,10 @@ static void ni_ao_fifo_load(struct comedi_device *dev,
                            struct comedi_subdevice *s, int n)
 {
        struct ni_private *devpriv = dev->private;
-       struct comedi_async *async = s->async;
-       struct comedi_cmd *cmd = &async->cmd;
-       int chan;
        int i;
        unsigned short d;
        u32 packed_data;
 
-       chan = async->cur_chan;
        for (i = 0; i < n; i++) {
                comedi_buf_read_samples(s, &d, 1);
 
@@ -1141,7 +1137,6 @@ static void ni_ao_fifo_load(struct comedi_device *dev,
                        /* 6711 only has 16 bit wide ao fifo */
                        if (!devpriv->is_6711) {
                                comedi_buf_read_samples(s, &d, 1);
-                               chan++;
                                i++;
                                packed_data |= (d << 16) & 0xffff0000;
                        }
@@ -1149,10 +1144,7 @@ static void ni_ao_fifo_load(struct comedi_device *dev,
                } else {
                        ni_writew(dev, d, DAC_FIFO_Data);
                }
-               chan++;
-               chan %= cmd->chanlist_len;
        }
-       async->cur_chan = chan;
 }
 
 /*
index 10886070f48c48504a5d46c471bf27c835591a1d..b13e9fb7a12e1f3b84ed0a1ca534515309e3fc48 100644 (file)
@@ -843,12 +843,8 @@ static bool pcl812_ai_next_chan(struct comedi_device *dev,
        struct pcl812_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
 
-       s->async->cur_chan++;
-       if (s->async->cur_chan >= cmd->chanlist_len) {
-               s->async->cur_chan = 0;
+       if (s->async->cur_chan == 0)
                devpriv->ai_act_scan++;
-               s->async->events |= COMEDI_CB_EOS;
-       }
 
        if (cmd->stop_src == TRIG_COUNT &&
            devpriv->ai_act_scan >= cmd->stop_arg) {
@@ -864,6 +860,7 @@ static void pcl812_handle_eoc(struct comedi_device *dev,
                              struct comedi_subdevice *s)
 {
        struct comedi_cmd *cmd = &s->async->cmd;
+       unsigned int chan = s->async->cur_chan;
        unsigned int next_chan;
        unsigned short val;
 
@@ -877,10 +874,8 @@ static void pcl812_handle_eoc(struct comedi_device *dev,
        comedi_buf_write_samples(s, &val, 1);
 
        /* Set up next channel. Added by abbotti 2010-01-20, but untested. */
-       next_chan = s->async->cur_chan + 1;
-       if (next_chan >= cmd->chanlist_len)
-               next_chan = 0;
-       if (cmd->chanlist[s->async->cur_chan] != cmd->chanlist[next_chan])
+       next_chan = s->async->cur_chan;
+       if (cmd->chanlist[chan] != cmd->chanlist[next_chan])
                pcl812_ai_set_chan_range(dev, cmd->chanlist[next_chan], 0);
 
        pcl812_ai_next_chan(dev, s);
index 053eed0474904da28188182fcb782c9fbe0f4a93..7cdb79826213fdb75bf3cc03f06c49beaf94d6f0 100644 (file)
@@ -289,12 +289,8 @@ static bool pcl816_ai_next_chan(struct comedi_device *dev,
        struct pcl816_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
 
-       s->async->cur_chan++;
-       if (s->async->cur_chan >= cmd->chanlist_len) {
-               s->async->cur_chan = 0;
+       if (s->async->cur_chan == 0)
                devpriv->ai_act_scan++;
-               s->async->events |= COMEDI_CB_EOS;
-       }
 
        if (cmd->stop_src == TRIG_COUNT &&
            devpriv->ai_act_scan >= cmd->stop_arg) {
index e6d897bf57145ca9b1b1c7bea722e32497e154c1..dc2715ae6b18c8eb832c520a3af46c935f944f36 100644 (file)
@@ -525,12 +525,8 @@ static bool pcl818_ai_next_chan(struct comedi_device *dev,
        if (devpriv->act_chanlist_pos >= devpriv->act_chanlist_len)
                devpriv->act_chanlist_pos = 0;
 
-       s->async->cur_chan++;
-       if (s->async->cur_chan >= cmd->chanlist_len) {
-               s->async->cur_chan = 0;
+       if (s->async->cur_chan == 0)
                devpriv->ai_act_scan--;
-               s->async->events |= COMEDI_CB_EOS;
-       }
 
        if (cmd->stop_src == TRIG_COUNT && devpriv->ai_act_scan == 0) {
                /* all data sampled */
index 19596756864de1874eaf2adfd2899392b8af4331..fb71fd60bc4e6d51c495af8d59a1c47febe24d79 100644 (file)
@@ -628,9 +628,6 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
                if (!comedi_buf_write_samples(s, &d, 1))
                        return -1;
 
-               async->cur_chan++;
-               async->cur_chan %= cmd->chanlist_len;
-
                if (devpriv->ai_count > 0)      /* < 0, means read forever */
                        devpriv->ai_count--;
        }