Commit 16c7eb60 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: adv_pci1710: always enable PCI171x_PARANOIDCHECK code

This define enables code that checks for analog input channel dropout
when reading samples. 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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e2d8c43b
...@@ -51,10 +51,6 @@ Configuration options: ...@@ -51,10 +51,6 @@ Configuration options:
#include "8253.h" #include "8253.h"
#include "amcc_s5933.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 */ /* hardware types of the cards */
#define TYPE_PCI171X 0 #define TYPE_PCI171X 0
#define TYPE_PCI1713 2 #define TYPE_PCI1713 2
...@@ -328,6 +324,26 @@ static const unsigned int muxonechan[] = { ...@@ -328,6 +324,26 @@ static const unsigned int muxonechan[] = {
0x1818, 0x1919, 0x1a1a, 0x1b1b, 0x1c1c, 0x1d1d, 0x1e1e, 0x1f1f 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, static int pci171x_ai_check_chanlist(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_cmd *cmd) struct comedi_cmd *cmd)
...@@ -410,17 +426,13 @@ static void setup_channel_list(struct comedi_device *dev, ...@@ -410,17 +426,13 @@ static void setup_channel_list(struct comedi_device *dev,
if (CR_AREF(chanlist[i]) == AREF_DIFF) if (CR_AREF(chanlist[i]) == AREF_DIFF)
range |= 0x0020; range |= 0x0020;
outw(range, dev->iobase + PCI171x_RANGE); /* select gain */ outw(range, dev->iobase + PCI171x_RANGE); /* select gain */
#ifdef PCI171x_PARANOIDCHECK
devpriv->act_chanlist[i] = devpriv->act_chanlist[i] =
(CR_CHAN(chanlist[i]) << 12) & 0xf000; (CR_CHAN(chanlist[i]) << 12) & 0xf000;
#endif
} }
#ifdef PCI171x_PARANOIDCHECK
for ( ; i < n_chan; i++) { /* store remainder of channel list */ for ( ; i < n_chan; i++) { /* store remainder of channel list */
devpriv->act_chanlist[i] = devpriv->act_chanlist[i] =
(CR_CHAN(chanlist[i]) << 12) & 0xf000; (CR_CHAN(chanlist[i]) << 12) & 0xf000;
} }
#endif
devpriv->ai_et_MuxVal = devpriv->ai_et_MuxVal =
CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen - 1]) << 8); CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen - 1]) << 8);
...@@ -446,12 +458,9 @@ static int pci171x_insn_read_ai(struct comedi_device *dev, ...@@ -446,12 +458,9 @@ static int pci171x_insn_read_ai(struct comedi_device *dev,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
struct pci1710_private *devpriv = dev->private; struct pci1710_private *devpriv = dev->private;
int ret; unsigned int chan = CR_CHAN(insn->chanspec);
int n; int ret = 0;
#ifdef PCI171x_PARANOIDCHECK int i;
const struct boardtype *this_board = comedi_board(dev);
unsigned int idata;
#endif
devpriv->CntrlReg &= Control_CNT0; devpriv->CntrlReg &= Control_CNT0;
devpriv->CntrlReg |= Control_SW; /* set software trigger */ devpriv->CntrlReg |= Control_SW; /* set software trigger */
...@@ -461,34 +470,27 @@ static int pci171x_insn_read_ai(struct comedi_device *dev, ...@@ -461,34 +470,27 @@ static int pci171x_insn_read_ai(struct comedi_device *dev,
setup_channel_list(dev, s, &insn->chanspec, 1, 1); setup_channel_list(dev, s, &insn->chanspec, 1, 1);
for (n = 0; n < insn->n; n++) { for (i = 0; i < insn->n; i++) {
unsigned int val;
outw(0, dev->iobase + PCI171x_SOFTTRG); /* start conversion */ outw(0, dev->iobase + PCI171x_SOFTTRG); /* start conversion */
ret = comedi_timeout(dev, s, insn, pci171x_ai_eoc, 0); ret = comedi_timeout(dev, s, insn, pci171x_ai_eoc, 0);
if (ret) { if (ret)
outb(0, dev->iobase + PCI171x_CLRFIFO); break;
outb(0, dev->iobase + PCI171x_CLRINT);
return ret;
}
#ifdef PCI171x_PARANOIDCHECK val = inw(dev->iobase + PCI171x_AD_DATA);
idata = inw(dev->iobase + PCI171x_AD_DATA); ret = pci171x_ai_dropout(dev, s, chan, val);
if (this_board->cardtype != TYPE_PCI1713) if (ret)
if ((idata & 0xf000) != devpriv->act_chanlist[0]) { break;
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
data[i] = val & s->maxdata;
} }
outb(0, dev->iobase + PCI171x_CLRFIFO); outb(0, dev->iobase + PCI171x_CLRFIFO);
outb(0, dev->iobase + PCI171x_CLRINT); outb(0, dev->iobase + PCI171x_CLRINT);
return n; return ret ? ret : insn->n;
} }
/* /*
...@@ -741,22 +743,20 @@ static void pci1710_handle_every_sample(struct comedi_device *dev, ...@@ -741,22 +743,20 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
{ {
struct pci1710_private *devpriv = dev->private; struct pci1710_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd; struct comedi_cmd *cmd = &s->async->cmd;
int m; unsigned int status;
#ifdef PCI171x_PARANOIDCHECK unsigned int val;
const struct boardtype *this_board = comedi_board(dev); int ret;
unsigned short sampl;
#endif
m = inw(dev->iobase + PCI171x_STATUS); status = inw(dev->iobase + PCI171x_STATUS);
if (m & Status_FE) { if (status & Status_FE) {
dev_dbg(dev->class_dev, "A/D FIFO empty (%4x)\n", m); dev_dbg(dev->class_dev, "A/D FIFO empty (%4x)\n", status);
s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
cfc_handle_events(dev, s); cfc_handle_events(dev, s);
return; return;
} }
if (m & Status_FF) { if (status & Status_FF) {
dev_dbg(dev->class_dev, dev_dbg(dev->class_dev,
"A/D FIFO Full status (Fatal Error!) (%4x)\n", m); "A/D FIFO Full status (Fatal Error!) (%4x)\n", status);
s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
cfc_handle_events(dev, s); cfc_handle_events(dev, s);
return; return;
...@@ -765,30 +765,16 @@ static void pci1710_handle_every_sample(struct comedi_device *dev, ...@@ -765,30 +765,16 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
outb(0, dev->iobase + PCI171x_CLRINT); /* clear our INT request */ outb(0, dev->iobase + PCI171x_CLRINT); /* clear our INT request */
for (; !(inw(dev->iobase + PCI171x_STATUS) & Status_FE);) { for (; !(inw(dev->iobase + PCI171x_STATUS) & Status_FE);) {
#ifdef PCI171x_PARANOIDCHECK val = inw(dev->iobase + PCI171x_AD_DATA);
sampl = inw(dev->iobase + PCI171x_AD_DATA); ret = pci171x_ai_dropout(dev, s, s->async->cur_chan, val);
if (this_board->cardtype != TYPE_PCI1713) if (ret) {
if ((sampl & 0xf000) != s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
devpriv->act_chanlist[s->async->cur_chan]) { break;
printk }
("comedi: A/D data dropout: received data from channel %d, expected %d!\n",
(sampl & 0xf000) >> 12, comedi_buf_put(s->async, val & s->maxdata);
(devpriv->
act_chanlist[s->
async->cur_chan] & 0xf000) >>
12);
s->async->events |=
COMEDI_CB_EOA | COMEDI_CB_ERROR;
cfc_handle_events(dev, s);
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;
s->async->cur_chan++;
if (s->async->cur_chan >= cmd->chanlist_len) if (s->async->cur_chan >= cmd->chanlist_len)
s->async->cur_chan = 0; s->async->cur_chan = 0;
...@@ -799,8 +785,7 @@ static void pci1710_handle_every_sample(struct comedi_device *dev, ...@@ -799,8 +785,7 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
devpriv->ai_act_scan >= cmd->stop_arg) { devpriv->ai_act_scan >= cmd->stop_arg) {
/* all data sampled */ /* all data sampled */
s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_EOA;
cfc_handle_events(dev, s); break;
return;
} }
} }
} }
...@@ -818,41 +803,27 @@ static int move_block_from_fifo(struct comedi_device *dev, ...@@ -818,41 +803,27 @@ static int move_block_from_fifo(struct comedi_device *dev,
{ {
struct pci1710_private *devpriv = dev->private; struct pci1710_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd; struct comedi_cmd *cmd = &s->async->cmd;
int i, j; unsigned int val;
#ifdef PCI171x_PARANOIDCHECK int ret;
const struct boardtype *this_board = comedi_board(dev); int i;
unsigned short sampl;
#endif
j = s->async->cur_chan;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
#ifdef PCI171x_PARANOIDCHECK val = inw(dev->iobase + PCI171x_AD_DATA);
sampl = inw(dev->iobase + PCI171x_AD_DATA);
if (this_board->cardtype != TYPE_PCI1713) ret = pci171x_ai_dropout(dev, s, s->async->cur_chan, val);
if ((sampl & 0xf000) != devpriv->act_chanlist[j]) { if (ret) {
dev_dbg(dev->class_dev, s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
"A/D FIFO data dropout: received data from channel %d, expected %d! (%d/%d/%d/%d/%d/%4x)\n", return ret;
(sampl & 0xf000) >> 12, }
(devpriv->act_chanlist[j] & 0xf000) >> 12,
i, j, devpriv->ai_act_scan, n, turn, comedi_buf_put(s->async, val & s->maxdata);
sampl);
s->async->events |= s->async->cur_chan++;
COMEDI_CB_EOA | COMEDI_CB_ERROR; if (s->async->cur_chan >= cmd->chanlist_len) {
cfc_handle_events(dev, s); s->async->cur_chan = 0;
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;
devpriv->ai_act_scan++; devpriv->ai_act_scan++;
} }
} }
s->async->cur_chan = j;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment