This define enables code that checks for analog input channel dropout
when reading sampled. The define is enabled so we might as well always
enable the code and remove the define.

Factor out the common channel dropout detect code as a helper function.
And cleanup the code.

Signed-off-by: H Hartley Sweeten <hswee...@visionengravers.com>
Cc: Ian Abbott <abbo...@mev.co.uk>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
---
 drivers/staging/comedi/drivers/adv_pci1710.c | 146 +++++++++++----------------
 1 file changed, 60 insertions(+), 86 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c 
b/drivers/staging/comedi/drivers/adv_pci1710.c
index 56186f0..a69a283 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -51,10 +51,6 @@ Configuration options:
 #include "8253.h"
 #include "amcc_s5933.h"
 
-#define PCI171x_PARANOIDCHECK  /* if defined, then is used code which control
-                                * correct channel number on every 12 bit
-                                * sample */
-
 /* hardware types of the cards */
 #define TYPE_PCI171X   0
 #define TYPE_PCI1713   2
@@ -327,6 +323,26 @@ static const unsigned int muxonechan[] = {
        0x1818, 0x1919, 0x1a1a, 0x1b1b, 0x1c1c, 0x1d1d, 0x1e1e, 0x1f1f
 };
 
+static int pci171x_ai_dropout(struct comedi_device *dev,
+                             struct comedi_subdevice *s,
+                             unsigned int chan,
+                             unsigned int val)
+{
+       const struct boardtype *board = comedi_board(dev);
+       struct pci1710_private *devpriv = dev->private;
+
+       if (board->cardtype != TYPE_PCI1713) {
+               if ((val & 0xf000) != devpriv->act_chanlist[chan]) {
+                       dev_err(dev->class_dev,
+                               "A/D data droput: received from channel %d, 
expected %d\n",
+                               (val >> 12) & 0xf,
+                               (devpriv->act_chanlist[chan] >> 12) & 0xf);
+                       return -ENODATA;
+               }
+       }
+       return 0;
+}
+
 static int pci171x_ai_check_chanlist(struct comedi_device *dev,
                                     struct comedi_subdevice *s,
                                     struct comedi_cmd *cmd)
@@ -411,17 +427,13 @@ static void setup_channel_list(struct comedi_device *dev,
                if (CR_AREF(chanlist[i]) == AREF_DIFF)
                        range |= 0x0020;
                outw(range, dev->iobase + PCI171x_RANGE); /* select gain */
-#ifdef PCI171x_PARANOIDCHECK
                devpriv->act_chanlist[i] =
                        (CR_CHAN(chanlist[i]) << 12) & 0xf000;
-#endif
        }
-#ifdef PCI171x_PARANOIDCHECK
        for ( ; i < n_chan; i++) { /* store remainder of channel list */
                devpriv->act_chanlist[i] =
                        (CR_CHAN(chanlist[i]) << 12) & 0xf000;
        }
-#endif
 
        devpriv->ai_et_MuxVal =
                CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen - 1]) << 8);
@@ -447,12 +459,9 @@ static int pci171x_insn_read_ai(struct comedi_device *dev,
                                struct comedi_insn *insn, unsigned int *data)
 {
        struct pci1710_private *devpriv = dev->private;
-       int ret;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       int ret = 0;
        int n;
-#ifdef PCI171x_PARANOIDCHECK
-       const struct boardtype *this_board = comedi_board(dev);
-       unsigned int idata;
-#endif
 
        devpriv->CntrlReg &= Control_CNT0;
        devpriv->CntrlReg |= Control_SW;        /*  set software trigger */
@@ -463,33 +472,26 @@ static int pci171x_insn_read_ai(struct comedi_device *dev,
        setup_channel_list(dev, s, &insn->chanspec, 1, 1);
 
        for (n = 0; n < insn->n; n++) {
+               unsigned int val;
+
                outw(0, dev->iobase + PCI171x_SOFTTRG); /* start conversion */
 
                ret = comedi_timeout(dev, s, insn, pci171x_ai_eoc, 0);
-               if (ret) {
-                       outb(0, dev->iobase + PCI171x_CLRFIFO);
-                       outb(0, dev->iobase + PCI171x_CLRINT);
-                       return ret;
-               }
+               if (ret)
+                       break;
 
-#ifdef PCI171x_PARANOIDCHECK
-               idata = inw(dev->iobase + PCI171x_AD_DATA);
-               if (this_board->cardtype != TYPE_PCI1713)
-                       if ((idata & 0xf000) != devpriv->act_chanlist[0]) {
-                               comedi_error(dev, "A/D insn data droput!");
-                               return -ETIME;
-                       }
-               data[n] = idata & 0x0fff;
-#else
-               data[n] = inw(dev->iobase + PCI171x_AD_DATA) & 0x0fff;
-#endif
+               val = inw(dev->iobase + PCI171x_AD_DATA);
+               ret = pci171x_ai_dropout(dev, s, chan, val);
+               if (ret)
+                       break;
 
+               data[n] = val & s->maxdata;
        }
 
        outb(0, dev->iobase + PCI171x_CLRFIFO);
        outb(0, dev->iobase + PCI171x_CLRINT);
 
-       return n;
+       return ret ? ret : insn->n;
 }
 
 /*
@@ -742,11 +744,9 @@ static void pci1710_handle_every_sample(struct 
comedi_device *dev,
 {
        struct pci1710_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
+       unsigned int val;
+       int ret;
        int m;
-#ifdef PCI171x_PARANOIDCHECK
-       const struct boardtype *this_board = comedi_board(dev);
-       unsigned short sampl;
-#endif
 
        m = inw(dev->iobase + PCI171x_STATUS);
        if (m & Status_FE) {
@@ -762,29 +762,16 @@ static void pci1710_handle_every_sample(struct 
comedi_device *dev,
        }
 
        for (; !(inw(dev->iobase + PCI171x_STATUS) & Status_FE);) {
-#ifdef PCI171x_PARANOIDCHECK
-               sampl = inw(dev->iobase + PCI171x_AD_DATA);
-               if (this_board->cardtype != TYPE_PCI1713)
-                       if ((sampl & 0xf000) !=
-                           devpriv->act_chanlist[s->async->cur_chan]) {
-                               printk
-                                   ("comedi: A/D data dropout: received data 
from channel %d, expected %d!\n",
-                                    (sampl & 0xf000) >> 12,
-                                    (devpriv->
-                                     act_chanlist[s->
-                                                  async->cur_chan] & 0xf000) >>
-                                    12);
-                               s->async->events |=
-                                   COMEDI_CB_EOA | COMEDI_CB_ERROR;
-                               return;
-                       }
-               comedi_buf_put(s->async, sampl & 0x0fff);
-#else
-               comedi_buf_put(s->async,
-                              inw(dev->iobase + PCI171x_AD_DATA) & 0x0fff);
-#endif
-               ++s->async->cur_chan;
+               val = inw(dev->iobase + PCI171x_AD_DATA);
+               ret = pci171x_ai_dropout(dev, s, s->async->cur_chan, val);
+               if (ret) {
+                       s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
+                       break;
+               }
 
+               comedi_buf_put(s->async, val & s->maxdata);
+
+               s->async->cur_chan++;
                if (s->async->cur_chan >= cmd->chanlist_len)
                        s->async->cur_chan = 0;
 
@@ -794,7 +781,7 @@ static void pci1710_handle_every_sample(struct 
comedi_device *dev,
                            devpriv->ai_act_scan >= cmd->stop_arg) {
                                /*  all data sampled */
                                s->async->events |= COMEDI_CB_EOA;
-                               return;
+                               break;
                        }
                }
        }
@@ -808,40 +795,27 @@ static int move_block_from_fifo(struct comedi_device *dev,
 {
        struct pci1710_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
-       int i, j;
-#ifdef PCI171x_PARANOIDCHECK
-       const struct boardtype *this_board = comedi_board(dev);
-       unsigned short sampl;
-#endif
+       unsigned int val;
+       int ret;
+       int i;
 
-       j = s->async->cur_chan;
        for (i = 0; i < n; i++) {
-#ifdef PCI171x_PARANOIDCHECK
-               sampl = inw(dev->iobase + PCI171x_AD_DATA);
-               if (this_board->cardtype != TYPE_PCI1713)
-                       if ((sampl & 0xf000) != devpriv->act_chanlist[j]) {
-                               dev_dbg(dev->class_dev,
-                                       "A/D FIFO data dropout: received data 
from channel %d, expected %d! (%d/%d/%d/%d/%d/%4x)\n",
-                                       (sampl & 0xf000) >> 12,
-                                       (devpriv->act_chanlist[j] & 0xf000) >> 
12,
-                                       i, j, devpriv->ai_act_scan, n, turn,
-                                       sampl);
-                               s->async->events |=
-                                   COMEDI_CB_EOA | COMEDI_CB_ERROR;
-                               return 1;
-                       }
-               comedi_buf_put(s->async, sampl & 0x0fff);
-#else
-               comedi_buf_put(s->async,
-                              inw(dev->iobase + PCI171x_AD_DATA) & 0x0fff);
-#endif
-               j++;
-               if (j >= cmd->chanlist_len) {
-                       j = 0;
+               val = inw(dev->iobase + PCI171x_AD_DATA);
+
+               ret = pci171x_ai_dropout(dev, s, s->async->cur_chan, val);
+               if (ret) {
+                       s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
+                       return ret;
+               }
+
+               comedi_buf_put(s->async, val & s->maxdata);
+
+               s->async->cur_chan++;
+               if (s->async->cur_chan >= cmd->chanlist_len) {
+                       s->async->cur_chan = 0;
                        devpriv->ai_act_scan++;
                }
        }
-       s->async->cur_chan = j;
        return 0;
 }
 
-- 
1.9.2

_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to